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]](Math3-S2-images/Math3-S2-Demo7_Newton_1.gif)
| > | newton_plot(x -> cos(x) - x, 0.5, 5): |
![[Plot]](Math3-S2-images/Math3-S2-Demo7_Newton_10.gif)
| > |