I want to show you a simple example of how ode45 works. I wrote simple solver like ode45
function main
clc
F = @(t,x) [x(2); x(1)-2*sin(x(1))];
ts = [0 5];
x0 = [0.5 1];
[t1,x] = ode45(F,ts,x0);
[t2, res] = new_ode45_solver(F,ts,x0);
h1 = plot(t1,x,'r');
hold on
h2 = plot(t2,res,'b');
hold off
legend([h1(1) h2(2)],'ode45 solver','my new ode45 solver')
end
function [t, res] = new_ode45_solver(F,ts,x0)
n = 100;
dt = (ts(2)-ts(1))/n;
res = zeros(n,2);
t = linspace(ts(1),ts(2),n)';
x = x0;
for i = 1:n
res(i,:) = x;
x = x + dt*F(t(i),x)';
end
end
Look at this line
Look here
dx(2)=-(OmegaR.^2/4).*sin(4*x(1))+2*Omegae.*gamma.*(Hy.*cos(x(1))-Hx.*sin(x(1)))-...
2*Omegae.*alpha.*x(2);
x(2) = [1 2 3]
ode45 works as loop. So if you pass some parameters (Hx,Hy) they can't be arrays
Best Answer