You are on page 1of 3

Metodo de Biseccion

clear

clc

f=input('ESCRIBA LA FUNCION QUE DEFINE LA ECUACIÓN = ','s');

i=input('ESCRIBA EL INTERVALO [a,b] = ');

TOL=input('ESCRIBA EL ERROR DE TOLERANCIA = ');

q= abs(log10(TOL));

fprintf('\n');

a=i(1);

b=i(2);

n= (log10(b-a)+q)/log10(2)+1;

y=inline(f);

i=1;

swa=0;

m=0;

FA=y(a);

fprintf('%9s','n','a','f(a)','b',' p',' f(p)',' (b-a)/2',' f(a)*f(p)');

fprintf('\n');

while i<=n

m=m+1;%contador de iteraciones para muestra en pantalla

p=a+(b-a)/2;

e=(b-a)/2;

FP=y(p);

if FA*FP >=0

t=('> 0');

else

t=('< 0');

end

fprintf('%9.0f',m);
fprintf('%9.3f ',a,FA,b,p,FP,e);

fprintf('%10s',t);

fprintf('\n');

if FP==0 ||(b-a)/2< TOL

swa=1;

t=('PARAR');

fprintf('\nLa raiz Deseada es: %.2f\n', p);

fprintf('se utilizaron %.0f iteraciones\n', m)

break

end

i=i+1;

swb=1;

if FA*FP > 0

a=p;

FA=FP;

else

b=p;

end

end

if swa==0

fprintf('\nEL METODO FRACASO DESPUES DE %.0f ITERACIONES\n PROCEDIMIENTO


TERMINADO SIN EXITO',m);

end
Metodo Newton Raphson

clc

clear

syms x;

x0=input('Ingrese el valor inicial: ');

tol=input('Ingrese el porcentaje de error: ');

f=input('Ingrese la función: ');

i=1;

fx(i)=x0;

f1=subs(f,x,fx(i));

z=diff(f);

d=subs(z,x,fx(i));

ea(1)=100;

while abs(ea(i))>=tol;

fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); d=subs(z,x,fx(i+1));

ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100);

i=i+1;

end

fprintf('i fx(i) Error aprox (i) \n');

for j=1:i;

fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j));

end

You might also like