Greetings,
I want to solve the following set of coupled ODEs:
I went ahead and used the following assumptions: [ y(1)=θ(t), y(2)=d(θ(t))/dt ,y(3)=φ(t) and y(4)=d(φ(t))/dt ] in order to later on employ the ode45 command to find the solution. Eventhough the script I made runs with no errors or issues, the output matrix y is filled with NaN (except the first row of course, which corresponds to the initial conditions given).
Could you please help me pin point the error in my code, or alternatively propose another method perhaps more suitable to solve these equations?
Thank you in advance!
Here's the script:
% Definition of Parameters
g=9.81; % m/s2
l= input('Strings length: ');
omega=(g/l);
Ttot=input('Total Simulation Time (sec): ');
% Initial Conditions
theta_0 = input('Theta_0 (in form of n*pi): ');
theta_t0 = input('Theta_t0: ');
phi_0 = input('Phi_0 (in form of n*pi): ');
phi_t0 = input('Phi_t0: ');
y0 = [theta_0, theta_t0, phi_0, phi_t0];
% Solution
f=@(t,y) Pendulum3D(t,y,omega);
[t,y]=ode45(f,[0 Ttot],y0);
% Function
function dy=Pendulum3D(t,y,omega)
dy=[y(2);(sin(y(1))*cos(y(1))*(y(4))^2)-omega*sin(y(1)); y(4); (-2*y(4)*y(2)*cot(y(1)))];
end
Best Answer