MATLAB: Solving sytem of ODE’s

MATLABodeode45ordinary differential equationsystem of ode

Hello!
I am currently working on a script which solves a system of 4 ODE's in matlab. The script doesn't seem to give the right output, is there anyone who can point me in the right direction on getting it to work? I included the system of ode's I want to solve and the code I am currently using.
M1 = 0.5
M2 = 0.3
D1 = 0.1
D2 = 0.3
P1 = 0.30*160e6
P2 = 0.20*160e6
a12 = 0.1
a21 = 6
% define first order ODE
f = @(t,z) [z(2); z(2)*(-D1/M1)+P1-(a12/M1)*sin(z(1)-z(3)); z(4); (-D2/M2)*z(4)+(P2/M2)-((a21/M2)*sin(z(3)-z(1)))]
%solve using ode45 function
[t,s] = ode45(f,[0 20],[0 0 0 0]);

Best Answer

The only problem I see is that ‘P1’ should be divided by ‘M1’ ...
f = @(t,z) [z(2); z(2)*(-D1/M1)+P1/M1-(a12/M1)*sin(z(1)-z(3)); z(4); (-D2/M2)*z(4)+(P2/M2)-((a21/M2)*sin(z(3)-z(1)))];
↑ ← HERE
Unless I’m misinterpreting your code.