% Antti Hannukainen
% 
% 
% Move on solution curve  f(x,a) = 0
% 
% function [u,v] = parc(u0,fu,Dfu,delta,v0)
% 
% u0    = inital point
% fu    = function 
% Dfu   = jacobian
% delta = length of the step
% v0    = optional direction ( tangent is used )
% 
% 
% return : u,v
% u = new point
% v = secant approxiation to tangent direction
%


function [u,v] = parc(u0,fu,Dfu,delta,v0)


% use svd to compute approximation to the tangent

if(nargin < 5)
  [U,S,V] = svd(Dfu(u0));
  
  v0 = V*[ zeros(length(u0)-1,1) ; 1];
  v0 = v0/norm(v0); 
end


% predictor
u = u0 + delta*v0;

% corrector
u = gnewton(u,fu,Dfu,@pifun);

v = (u-u0)/norm(u-u0);
