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); |
(1) |
> | diff(f(x),x); |
(2) |
> | fp := x->tan(x)+x*(1+tan(x)^2):
'diff(f(x),x)' = fp(x); |
(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; |
(4) |
> | # Check our answer...
x[n]*tan(x[n])=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); |
(6) |
Using Maple's "NewtonsMethod" command...
> | with(Student[Calculus1]): |
> | NewtonsMethod(x*tan(x)-1, x = 1); |
(7) |
> | NewtonsMethod(x*tan(x)-1, x = 1, output = sequence); |
(8) |
> | NewtonsMethod(x*tan(x)-1, x = 1, view = [0.8..1.1, DEFAULT], output = plot); |
> | NewtonsMethod(x*tan(x)-1, x = 1, view = [0.8..1.1, DEFAULT], output = animation); |
> | NewtonsMethod(x^3 - x, x = 2, view = [0..3, DEFAULT], output = plot); |
> | NewtonsMethod(x^3 - x, x = 2, output = animation); |
> | NewtonsMethod(x^2 + x + 1, x=2, output=animation,iterations = 15); |
> | ? NewtonsMethod |
> |