Vous êtes sur la page 1sur 2

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

clc
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)
n
0

a
-2.0000

-1.0800

c
b
-1.0000 100.0000

1.0000

-2.0000

-1.1254

-1.0800

1.1953

2.0000

-2.0000

-1.1499

-1.1254

0.6605

3.0000

-2.0000

-1.1626

-1.1499

0.3492

4.0000

-2.0000

-1.1691

-1.1626

0.1803

5.0000

-2.0000

-1.1724

-1.1691

0.0920

6.0000

-2.0000

-1.1741

-1.1724

0.0466

7.0000

-2.0000

-1.1749

-1.1741

0.0236

8.0000

-2.0000

-1.1753

-1.1749

0.0119

9.0000

-2.0000

-1.1756

-1.1753

0.0060

10.0000

-2.0000

-1.1757

-1.1756

0.0030

11.0000

-2.0000

-1.1757

-1.1757

0.0015

12.0000

-2.0000

-1.1758

-1.1757

0.0008

13.0000

-2.0000

-1.1758

-1.1758

0.0004

error

14.0000

-2.0000

-1.1758

-1.1758

0.0002

raiz encontrada con una tolerancia de 0.000100:


ans =
-1.1758

Vous aimerez peut-être aussi