% Broyden method for the roots of 
% a set of nonlinear equations
% Requires no explicit computation of Jacobian
% See example 5.16 on p.242 of Heath
% This version is not efficient since we must solve 
% a linear system within each loop, O (n^3) ops.
% K. Ming Leung, 02/05/03
 
clear all; format long;
maxIt=200; 
tol=eps; 

it=0; 
err=1;
x=[1 2]';
B=feval('fcnJEg5p15',x);
fk=feval('fcnEg5p15',x),
while it < maxIt & err > tol
    s=-B\fk;
    x=x+s;
    err=s.'*s; %norm(s,inf);
    if err > tol
        fk=feval('fcnEg5p15',x);
        B=B+(1/(s'*s))*fk*s';
    end
    it=it+1;
end

