I programmed a Nystrom Algorithm specifically for my problem:
This is the exact equation i want to solve:
$y''=(w^2-e*cos(t))*sin(t)-b*y'$
And this is my algorithm
function [T U] = Nystrom(a,b,u0,h,w,v,e)
% a is the initial value
% b is the final value
% u0 is a vector with the initial conditions y(0) and y'(0)
% h is the size of every step
% w, v and e are constants.
M=(b-a)/h+2; %Steps
T=zeros(1,M+2); %Time vectors
U=zeros(2,M+2); %y and y' vector
T=a:h:b; % i use uniform steps of size h
U(:,1)=u0; %i stablish the initial conditions
U(1,2)=U(1,1)+h*U(2,1)+(h^2)/2 * (w^2-e*cos(T(1))*sin(U(1,1))-v*U(2,1));
for i=3:M
U(1,i)=(-2*U(1,i-1)+U(1,i-2)-h^2*(w^2-e*cos(T(i-1)))*sin(U(1,i-1))-h*v*(U(1,i-2))/2)/(1-h*v/2);
end
for i=1:M
U(2,i+1)=(U(1,i+2)-U(1,i))/(2*h);
end
U=U';
T=T';
The problem is, it doesn't work and i don't know why. It's throwing values bigger and bigger in every step, but solving the same problem with other methods gives different, quite smaller values.
Any idea could help. Thank you!