clc clear all a=input('ingresar el valor de a='); b=input('ingresar el valor de b='); error=input('ingresar el error='); Fa=a^3-sin(a^2); Fb=b^3-sin(b^2); mierrorpaso=error+1; while(mierrorpaso>error) m=(a+b)/2; Fm=m^3-sin(m^2); if Fm*Fa<0; b=m; Fb=Fm; else a=m; Fa=Fm; end mierrorpaso=abs(Fm); end disp(la respuesta es=’) disp(m) MÉTODO DE NEWTON-RAPHSON
Resolviendo la ecuación 𝑓 (𝑥 ) = 𝑥 3 − (ln 𝑥) ∗ sin 𝑥 2
Sabiendo que: 𝑓(𝑥1) 𝑥2 = 𝑥1 − 𝑓′(𝑥1) clc clear all x1=input('ingresar el valor aproximado='); E=input('ingrese el error='); N=0; error=E+1 while (error>E) x2=x1-(x1^3-log(x1)*sin(x1^2))/(3*x1^2- ((sin(x1^2)/x1)+cos(x1^2)*2*x1*log(x1))); error=abs(x2-x1); x1=x2; N=N+1; if (N>100) error('la solucion no converge'); end end disp('la respuesta es=') disp(x2) MÉTODO DE LA SECANTE
Resolviendo la ecuación 𝑓(𝑥 ) = 𝑥 3 + 4𝑥 2 − 10
𝑓(𝑥1)∗(𝑥0−𝑥1) Sabiendo: 𝑥2 = 𝑥1 − 𝑓 (𝑥0)−𝑓(𝑥1) clc clear all x0=input('ingresar el valor de x0='); x1=input('ingresar el valor de x1='); etol=input('ingresar el error de aproximacion='); nmax=input('ingresar el numero maximo de iteraciones='); error=etol+1; i=0; while error>etol || i<=nmax i=i+1; Fx0=Myfuncion(x0); Fx1=Myfuncion(x1); x2=x1-Fx1*(x0-x1)/(Fx0-Fx1); error=abs(x2-x1); x0=x1; x1=x2; end disp('la respuesta es =') disp(x2)
En otro script: function z=Myfuncion(x) z=x^3+4*x^2-10 end