% Duffing oscillator
%


% Find fixed point of pointcare map with 
% path following (respect to gamma) + Newton's iteration 
%

x   = [0;0];
tan = [0;0];
del = 0.001;

for gamma = 0:del:0.05

  x = x + tan;
  
  for i=1:100
    
    dx = ( Dapprox( @(s)(pMap(s,gamma)-s),x) )\(pMap(x,gamma)-x)
    x= x -dx;
    
    if(norm(dx) < 1e-6)
      disp('Newton converged!');
      break;
    end
  
  end
  
  tan = -del*Dapprox( @(s)(pMap(s,gamma)-s),x)\(pMap(x,gamma)-x);
  
 end

% Study S/U-manifolds near x (i.e. fixed point) !

Wu_g(x,5,@(x)(pMap(x,0.05)),'r--')
hold on;
Wu_g2(x,5,@(x)(pMap(x,0.05)),'r--')
hold on;
Wu_g(x,2,@(x)(pMapInv(x,0.05)))
hold on;
Wu_g2(x,2,@(x)(pMapInv(x,0.05)))

%[WU,WS] = f_map(@(x)(pMap(x,0.05)),x);
