function w = Newton %MATLAB routine for visualizing the workings of Newton's method %Created by Winfried Just, department of Mathematics, Ohio University %Last modified: January 28, 2003 syms x disp(' ') input('Enter the formula for your function. \n'); f = ans g = diff(f); disp(' ') input('Enter the initial value of x. \n'); x0 = ans disp(' ') input('Enter the left endpoint of your interval for $x$. \n'); a = ans disp(' ') input('Enter the right endpoint of your interval for $x$. \n'); b = ans disp(' ') input('Enter the lower limit of the y-axis. \n'); c = ans disp(' ') input('Enter the upper limit of the y-axis. \n'); d = ans y = subs(f, x0); hold off; ezplot('0', [a,b]) hold on; ezplot(f, [a,b]) axis([a b c d]) while 0 < 1 disp(' ') disp('Hit ENTER to continue of Ctrl^C to quit') pause m = subs(g, x0); %the slope of f at x0 y = subs(f, x0); %the value f(x0) h = m*(x-x0) + y; ezplot(h, [a,b]) x0 = x0 - y/m; axis([a b c d]) disp('The current approximation is:') disp(x0) end