ROOTFINDING
Secant Method
www.jesus-avalos.ucoz.com
ALGORITHM CODE:
SecantMethod[x0_,x1_,max_]:=Module[{},k=1;p0=N[x0];p1=N[x1];
Print["p0=",PaddedForm[p0,{16,16}]", f[p0]=",NumberForm[f[p0],16]];
Print["p1=", PaddedForm[p1,{16,16}],", f[p1]=", NumberForm[f[p1],16]];
p2=p1;
p1=p0;
While[k<max, p0=p1;p1=p2; p2=p1-(f[p1](p1-p0))/(f[p1]-f[p0]);
k=k+1;
Print["p "k, "=", PaddedForm[p2,{16,16}],", f[","p"k,"]=",NumberForm[f[p2],16]];];
Print["p =",NumberForm[p2,16]];
Print[" Δp=±"Abs[p2-p1]];
Print["f[p]=",NumberForm[f[p2],16]];]
EXAMPLE:
f[x_]=x^3+x-1
-1+x+x3
SecantMethod[0,1,9]
p0= , f[p0]= 0.0000000000000000 -1.
p1= 1.0000000000000000 , f[p1]= 1.
2 p = 0.5000000000000000 , f[ 2 p ]= -0.375
3 p = 0.6363636363636363 , f[ 3 p ]= -0.1059353869271225
4 p = 0.6900523560209423 , f[ 4 p ]= 0.01863614179998446
5 p = 0.6820204196481856 , f[ 5 p ]= -0.000736518493373528
6 p = 0.6823257814098928 , f[ 6 p ]= -4.847148849740357*10-6
7 p = 0.6823278043590257 , f[ 7 p ]= 1.272670357987948*10-9
8 p = 0.6823278038280184 , f[ 8 p ]= -2.275957200481571*10-15
9 p = 0.6823278038280193 , f[ 9 p ]= 1.665334536937735*10-16
p= 0.6823278038280193
9.99201*10-16 Δp=±
f[p]= 1.665334536937735*10-16
Plot[-1+x+x3,{x,0,1}]
|