% secant method
% See example 5.12 on p.232 of Heath
% looking for the root 1.93375376282702
% K. Ming Leung, 02/03/03

clear all; format long;
tol=eps;   % tolerance
x0=1;       % initial guess
x1=3;       % initial guess
dx=1;       % change in x
result=[];  % to store intermediate results
loop=1;
f0=x0*x0-4*sin(x0);         % f(x0)n
while abs(dx)> tol;
    f1=x1*x1-4*sin(x1);     % f(x1)
    dx=-f1*(x1-x0)/(f1-f0); % change in x
    x0=x1;                  % replace x0 by x1
    f0=f1;                  % replace f0 by f1
    x1=x1+dx,               % update x1
    result=[result; [loop x1 f1 dx]];
    loop=loop+1;
end;
display(result);

