secant method in maple

1.9k Views Asked by At

secant method in maple. Find a root of the statement $x^3-3x^2+4x-1=0$ with the initial value $x_0=0$ and $x_1=1$ with 5 digits point approximation.

2

There are 2 best solutions below

1
On BEST ANSWER

If this is homework and you're supposed to program it yourself then you could show what you've accomplished on your own already.

If you just want to see answers from such an algorithm then you could use the Student:-NumericalAnalysis command. Eg,

[Student:-NumericalAnalysis:-Secant(x^3-3*x^2+4*x-1,x=[0,1],
                                    tolerance=1e-5,
                                    maxiterations=50)]:
evalf[5](%)[];

                                0.31767


[Student:-NumericalAnalysis:-Secant(x^3-3*x^2+4*x-1,x=[0,1],
                                    tolerance=1e-5,
                                    output=sequence,
                                    maxiterations=50)]:
evalf[5](%)[];

 0., 1., 0.50000, 0.20000, 0.33624, 0.31947, 0.31764, 0.31767, 0.31767

Programming questions about Maple are better asked on stackoverflow, unless it is the mathematics behind the algorithm that is your central concern.

0
On

another one:

eps_step := 0.00001;

eps_abs := 0.00001;

f := x -> x^3-3*x^2+4*x-1;

x[0] := 1.0;

x[1] := 1.5;

for i from 2 to 100 do

x[i] := (x[i - 2]*f(x[i - 1]) - x[i - 1]*f(x[i - 2]))/(f(x[i - 1]) - f(x[i - 2]));

if abs( x[i] - x[i - 1] ) < eps_step and abs( f( x[i] ) ) < eps_abs then

eps_abs then break;

elif i = 100 then

end if;

end do:

evalf(x[i],5);

eps_step := 0.00001

eps_abs := 0.00001

                 f := x -> x^3-3*x^2+4*x-1

                     x[0] := 1.0

                     x[1] := 1.5

                        0.31767