% newton.m 
%
% Implements Newton's method.
% 
% This codes solves equation (1) of problem 1, problem set 1. 
%
% You will have to change `x' and `nmax' and the functions `f' and `df'
% if you wish to solve the other problems.

x = 0.5;
nmax = 10;

for n = 1:nmax
   f  = x^3 - 3*x + 1;
   df = 3*x^2 - 3;
   x  = x - f / df;
   fprintf('n=%3d   x=%15.12f  f(x)=%9.2e\n', n, x, f)
end
