Maple Examples
Newton's Method
The following procedure implements Newton's method to find the root of the equation f(x)=0 correct to n decimal places, starting with an initial approximation x0.
> Newt:=proc (f,x0,n) local x; x:=x0; while f(x-0.5*0.1^n)*f(x+0.5*0.1^n)>0 do x:=x-f(x)/D(f)(x) od end:
Exercise 19 (p. 174).
.
> f:=x->x^4+3*x^3-x-10:
> plot(f(x),x=-4..2);
> Newt(f,-3.2,8);
> Newt(f,1.4,8);
> fsolve(f(x)=0);
Exercise 20 (p. 174).
.
> f:=x->x^9-x^6+2*x^4+5*x-14:
> plot(f(x),x=-2..2);
> Newt(f,1.2,8);
> fsolve(f(x)=0);
Exercise 21 (p. 174).
.
> f:=x->sqrt(x^2-x+1)-2*evalf(sin(Pi*x)):
> plot(f(x),x=-2..2);
> Newt(f,0.2,8);
> Newt(f,0.8,8);
> fsolve(f(x)=0,x=0..0.5);
> fsolve(f(x)=0,x=0.5..1);
Exercise 22 (p.174).
.
> f:=x->cos(x^2+1)-x^3:
> plot(f(x),x=-2..2);
> Newt(f,0.6,8);
> fsolve(f(x)=0);