%Newton's Method Demo
clf
f = @(x) x.^3 +5;
df = @(x) 3*(x.^2);

x = [-5:0.01:1];

N_max = 7; %max number of iterates

x0 = -5; %initial guess
xn = zeros(N_max+1,1);
xn(1) = x0;
figure(1);
plot(x,f(x),x,0*x,xn(1),f(xn(1)),'r*',x,f(xn(1)) + df(xn(1))*(x-xn(1)))
axis([-5 1 -130 100])
title('Newton''s Method Demo')
pause

for i=1:N_max 
    xn(i+1) = xn(i) - f(xn(i))/df(xn(i));
    plot(x,f(x),x,0*x,xn(i+1),f(xn(i+1)),'r*',x,f(xn(i+1)) + df(xn(i+1))*(x-xn(i+1)));
    title('Newton''s Method Demo')
    axis([-5 1 -130 100])
    pause
end




