%%NEWTON.M  Newton's method for nonlinear root-finding. 
% NH 2019
f = @(t) 8 - 4.5*(t - sin(t)); % Define function
fp = @(t) -4.5*(1 - cos(t));   % Define derivative (hand computation)
x = 2.2;                       % Initial guess
disp([x f(x)])
for k = 1:4                    % <- different stopping criteria?
    x = x - f(x)./fp(x);       % Newton formula
    disp([x f(x)])
end

% Exercise: Rewrite to use a relative error stoping criteria.
