I'm trying to numerically evaluate a coupled ODE using MATLAB. The system I'm moddeling is a crane (mass $m_t$) with a hanging load (mass $m_p$, Inertia $I$ at distance $l$ under the crane). I have a function $u(t)$ that applies a force in the $x$ direction (horizontal) on the crane.
I've already determined (and double checked) the ODE's, which are:
$$(I+m_pl^2)\ddot{\theta}+m_pgl\sin(\theta)=-m_pl\ddot{x}\cos(\theta)$$ $$(m_t+m_p)\ddot{x}+b\dot{x}+m_pl\ddot{\theta}\cos(\theta)-m_pl\dot{\theta}^2\sin(\theta)=u$$
Trying to put this in MATLAB I do this:
b = 0.1;
l = 1;
m_p = 1;
m_t = 1;
g = 9.81;
I = 1;
function f = u_tFn(t)
f = zeros(size(t));
f(t>0 & t<1) = 1;
end
function dstatedt = ode(t, state)
theta = state(1);
dthetadt = state(2);
d2thetadt2 = (-m_p*g*l*sin(theta)-m_p*d2xdt2*l*cos(theta))/(m_p*l^2+I);
x = state(3);
dxdt = state(4);
d2xdt2 = (-b*dxdt-m_p*l*d2thetadt2*cos(theta)+m_p*l*dthetadt^2*sin(theta)+u_tFn(t))/(m_t+m_p);
dstatedt = [dthetadt;d2thetadt2;dxdt;d2xdt2];
end
But that doesn't work... As you can see, the problem is that $\ddot{\theta}$ is dependent on $\ddot{x}$ and vice versa $\ddot{x}$ is dependent on $\ddot{\theta}$.
How should I approach this problem?
Ok, so J. M. is not a mathematician helped me find an answer.
As he writes, you can seperate the system into linear equations. $$\begin{pmatrix}I+m_pl^2&m_pl\cos(\theta)\\m_pl\cos(\theta)&m_t+m_p\end{pmatrix}\begin{pmatrix}\ddot{\theta}\\\ddot{x}\end{pmatrix}=\begin{pmatrix}-m_pgl\sin(\theta)\\u+m_pl\dot{\theta}^2\sin(\theta)-b\dot{x}\end{pmatrix}$$
And of course $\begin{pmatrix}a&b\\c&d\end{pmatrix}^{-1}=\frac{1}{ab-cd}\begin{pmatrix}d&-b\\-c&a\end{pmatrix}$
So $$\begin{pmatrix}\ddot{\theta}\\\ddot{x}\end{pmatrix}= \frac{1}{I(m_p+m_t)+l^2m_p(m_p\sin^2(\theta)+m_t)} \begin{pmatrix}m_p+m_t&-lm_p\cos(\theta)\\-lm_p\cos(\theta)&m_pl^2+I\end{pmatrix} \begin{pmatrix}-m_pgl\sin(\theta)\\u+m_pl\dot{\theta}^2\sin(\theta)-b\dot{x}\end{pmatrix}$$
Which removes the cyclic dependencies. So I changed my MATLAB code to:
But then decided I can have MATLAB solve this for me (gives more readable code imho)
Still, I very much appreciate the hints on how to approach this problem. Thank you!