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): |
> | newton_plot(x -> cos(x) - x, 0.5, 5): |
> |