%two examples where Newton's method fails
%for f, estimates run off to infinity if initial estimate is too large
%for g, estimates alternate between +-1 if initial estimate is +-1

f = @(x) x/(1+x^2);
f_p = @(x) (1-x^2)/(1+x^2)^2;
g = @(x) x^3-5*x;
g_p = @(x) 3*x^2-5;
x = zeros(1,10);
y = zeros(1,10);

n = 10;     %n = number of iterations + 1

x(1) = 1.5;      %initial guess
for i=1:n
    x(i+1) = x(i) - f(x(i))/f_p(x(i));    %root estimates for f
end

y(1) = 1;      %initial guess
for i=1:n
    y(i+1) = y(i) - g(y(i))/g_p(y(i));    %root estimates for g
end

disp('estimates of root for f...')
x
disp('estimates of root for g...')
y
