% Modified predcorr -function
% 
% use QR - right inverses instead of the
% stationary Newton => Huge difference !
% 


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

% Tangent predictor
a1= a + Del;
x1= x + tan*Del; 
tol=1.e-10; 

% Setting for gnewton.m
ff =  @(x)( fn(x,a1));
Dff = @(x)(fxn(x,a1));

x1 = gnewton(x1,ff,Dff);

k = 0;

% Next step as in lecture noted
Del=2^((4-k)/3)*Del;

if (norm( ff(x1) ) >tol),  
  a1=a; x1=x; tan=tan; % corrector failed, reset 
else
  x=x1; a=a1; tan= -qrifun(Dff(x1),fan(x,a)); 
end
   

