Solve coupled second order differential equation with ODE 45

Hello,
I try to solve the coupled second order differential equations with ODE45 but I am facing problems when I write the set of equations in matlab.
I have 3 coupled second order differential equations as follows:
Therefore I changed the above equations with:
Then, to write the set of equations in Matlab I have:
Equations=@(tau,x) [x(2); -gamma_x*x(2)-alpha_x*x(1)-a*(Theta_1"*cos(x(3))-x(4)*2*sin(x(3))+Theta_2"*cos(x(5))-x(6)*2*sin(x(5)));
x(4); -x"* cos(x(3))-(1-ommega^2*p*sin(ommega*tau))*sin(x(3))-gamma_theta*x(4);
x(6); -x"* cos(x(5))-(1-ommega^2*p*sin(ommega*tau))*sin(x(5))-gamma_theta*x(6)]
So the problem I am facing is to write the terms in bold in Matlab since: x"=x2' , Theta_1"=x4' and Theta_2"=x6'.
Thank you.

Answers (1)

This looks like the old nugget of wisdom "Programs are meant to be read by humans and only incidentally for computers to execute" (forgotten the source).
First you might have to actually solve for the second derivatives of your x and theta1 and theta2s, to get some explicit expressions for the accelerations. If you have access to the symbolic toolbox that might be helpful, otherwise, pen and paper (pencil also an option) will work
The code in your dynamic function becomes too complicated to read. I suggest you write it in a .m-file as a matlab-function. Perhaps something like this:
function dXthetadt = your_odes(t,xNtheta)
x = xNtheta(1);
dxdt = xNtheta(2);
theta1 = xNtheta(3);
dtheta1dt = xNtheta(4);
theta2 = xNtheta(5);
dtheta2dt = xNtheta(6);
dXthetadt = [dxdt;
f4d2xdt2(x,dxdt,theta1,dtheta1dt,theta2,dtheta2dt,other,params);
etc_to;
handle_the;
thetas];
end
HTH

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!