
%-------------------------------
% El método de Newton-Raphson intenta
% resolver de forma iterativa la 
% solución de la ecuacion 
% f(x,y)  =  0 mediante la fórmula recursiva
% x     =  xold + Dx
% Dx    =  -f(x,y)/DfDx(x,y)
%-------------------------------
%    [y(itime),iter,Res]  =  MyNewtonRaphsonODE(g,Dg,tol,NMaxIter,y(itime-1),y(itime-1),t,Dt);

function [y,iter,Res]  =  MyNewtonRaphsonODE(g,Dg,tol,NMaxIter,yn,t,Dt)
  
  
Res                    =  zeros(NMaxIter,1);
iter                   =  0; 
y                      =  yn;  
while and(norm(g(y,yn,t,Dt))>tol,iter<NMaxIter) 
  iter                 =  iter + 1;
  Res(iter)            =  norm(g(y,yn,t,Dt));
  Dy                   =  -Dg(y,t,Dt)\g(y,yn,t,Dt);  %  Solver Directo de Octave
  y                    =  y + Dy;  
end 
Res(iter+1)            =  norm(g(y,yn,t,Dt));
if iter+1<NMaxIter
   Res(iter+2:end)     =  [];
end
iter                   =  iter + 1;

if iter>=NMaxIter
   fprintf('Solution not converged\n')
end