function [x,a,Del,tan]=predcorr(x,a,Del,tan,fn,fxn,fan)

lxb = @(A,b)(A\b);
uxb = @(A,b)(A\b);

a1=a+Del;
x1=x+tan*Del; 
k=0;
tol=1.e-10; 
f=feval(fn,x1,a1); 
J=feval(fxn,x1,a1); 
[l,u,p]=lu(J);
while (k<=7) & (norm(f)> tol),  % stationary Newton
  s=-p*f; s=lxb(l,s); s=uxb(u,s);   % triangular solves
  x1=x1+s; f=feval(fn,x1,a1); k=k+1;
end

Del=2^((4-k)/3)*Del; % next step to be tried

if (norm(f) >tol),  
  a1=a; x1=x; tan=tan; % corrector failed, reset 
else
  x=x1; a=a1; tan= -p*feval(fan,x,a); tan=lxb(l,tan); tan=uxb(u,tan); 
end;
   

