%%SECANT.M  Secant method for nonlinear root-finding. 
% NH 2019
f = @(t) 8 - 4.5*(t - sin(t)); % Define function
x = 2.2;                       % First guess
disp([x, f(x)]);
x(2,1) = 2.3;                  % Second guess
disp([x(2), f(x(2))]);
for n = 2:6
    x(n+1) = x(n) - f(x(n))*(x(n)-x(n-1))/(f(x(n))-f(x(n-1))); % <- inefficient!
    disp([x(n+1), f(x(n+1))]);
end

% Exercise: Rewrite the above to avoid unnecessary function evaluations.
