Newton's Method in Maple... 

Source file: math1110-summer2014-newtons_method.mw 

 

Choose "EditExecuteWorksheet" to see results of computations. 

 

[Ostebee & Zorn's Calculus 4.6 #6] Approximate the solution of  "x tan(x) = 1" on the interval [0,pi/2] using Newton's method. 

 

> f := x -> x*tan(x)-1:
'f(x)' = f(x);
 

f(x) = `+`(`*`(x, `*`(tan(x))), `-`(1)) (1)
 

> diff(f(x),x);
 

`+`(tan(x), `*`(x, `*`(`+`(1, `*`(`^`(tan(x), 2)))))) (2)
 

> fp := x->tan(x)+x*(1+tan(x)^2):
'diff(f(x),x)' = fp(x);
 

diff(f(x), x) = `+`(tan(x), `*`(x, `*`(`+`(1, `*`(`^`(tan(x), 2)))))) (3)
 

> # We'll iterate n times.
n := 4:

# Our initial guess is 1.
x[0] := 1;

for i from 1 to n do
  'f' = evalf(f(x[i-1]));
  'df/dx' = evalf(fp(x[i-1]));

   x[i] := evalf(x[i-1] - f(x[i-1])/fp(x[i-1])):
end do;
 

 

 

 

 

 

 

 

 

 

 

 

 

1
f = .557407725
`/`(`*`(df), `*`(dx)) = 4.982926547
.8881364757
f = 0.92324625e-1
`/`(`*`(df), `*`(dx)) = 3.461499664
.8614646184
f = 0.3608368e-2
`/`(`*`(df), `*`(dx)) = 3.195673222
.8603354767
f = 0.6012e-5
`/`(`*`(df), `*`(dx)) = 3.185031007
.8603335891 (4)
 

> # Check our answer...
x[n]*tan(x[n])=1;
 

1.000000000 = 1 (5)
 

> # Our solutions...
print("Newton's Method:");
for i from 0 to n do
  x[i];
end do;

# Maple's solution...
print("Maple's solution:");
fsolve(x*tan(x)=1,x=1);
 

 

 

 

 

 

 

 

Newton's Method:
1
.8881364757
.8614646184
.8603354767
.8603335891
Maple's solution:
.8603335890 (6)
 

 

Using Maple's "NewtonsMethod" command... 

 

> with(Student[Calculus1]):
 

> NewtonsMethod(x*tan(x)-1, x = 1);
 

.8603335891 (7)
 

> NewtonsMethod(x*tan(x)-1, x = 1, output = sequence);
 

1, .8881364757, .8614646184, .8603354767, .8603335891 (8)
 

> NewtonsMethod(x*tan(x)-1, x = 1, view = [0.8..1.1, DEFAULT], output = plot);
 

Plot_2d
 

> NewtonsMethod(x*tan(x)-1, x = 1, view = [0.8..1.1, DEFAULT], output = animation);
 

Plot_2d
 

> NewtonsMethod(x^3 - x, x = 2, view = [0..3, DEFAULT], output = plot);
 

Plot_2d
 

> NewtonsMethod(x^3 - x, x = 2, output = animation);
 

Plot_2d
 

> NewtonsMethod(x^2 + x + 1, x=2, output=animation,iterations = 15);
 

Plot_2d
 

> ? NewtonsMethod
 

>