Math3-S2-Demo7_Newton.mw

Math 3 Winter 2004

Introduction to Calculus


Class Demo for the Newton's Method

February 9, 2004


   
Define a procedure for plotting a function

    and approximating its root using Newton's Method

> newton_plot := proc (f, xstart, n)
local fp, i, x:


print(plot(f(x), x = -1..2)):

fp := diff(f(x), x):


x := xstart:

print (x):

for i from 1 to n do

x := evalf(x - f(x) / fp(x)):

print(x):

od:

end:

> newton_plot (x -> x^6 - 2, 1, 7):

[Plot]

1

1.166666667

1.126443678

1.122497067

1.122462051

1.122462048

1.122462048

1.122462048

> newton_plot(x -> cos(x) - x, 0.5, 5):

[Plot]

.5

.7552224170

.7391416661

.7390851339

.7390851332

.7390851332

>