Vous êtes sur la page 1sur 1

function y=f_falsapos(h, a,b,tol)

f=inline(h);
c=0; n=0; error=100;
fprintf('\t n\t\ta\t\t c\t\tb\t\terror\n')
x=a-5:0.02:b+5;
y=f(x);
z=zeros(size(x));
plot(x,y)
grid on,hold on
plot(x,z,'r')
while ( error > tol )
c=(a*f(b)-b*f(a))/(f(b)-f(a));
disp([n,a,c,b,error])
if(f(a)*f(c)<0)
b=c;
else
a=c;
end
error=abs(f(c));
n=n+1;
end
fprintf('raiz encontrada con una tolerancia de %f:\n', tol)
y=c;
f_falsapos('3*x.^3-4*x.^2-8*x+1',-2,-1,0.0001)

Vous aimerez peut-être aussi