# Lagrangian of three-mass system with Mathematica

Before proceeding to calculations in Mathematica, I would like to clarify with knowledgeable people.

There is an ordinary linear three-mass system.

If we write its Lagrangian, we get the following equation.

where $$W_k$$ and $$W_n$$ - kinetic and potential energy.

To find the moment of rotation of the first mass, we must differentiate lagrangian first by the angle of rotation of the first mass $$\phi_1$$, then find the rate of change in time of the Lagrangian derivative with respect to speed $$\omega_1$$.

Suppose we want to find the moment of the first mass $$J_1$$ (we assume that on the shaft of the drive motor).

$$\frac{\partial L}{\partial q} = \frac{\partial L}{\partial \phi_1} = -c_{12} (\phi_1 - \phi_2)$$

$$\frac{d}{dt}\frac{\partial L}{\partial \dot{q}} = \frac{d}{dt}\frac{\partial L}{\partial \omega_1} = J_1 \frac{\partial \omega_1}{\partial t}$$

Which ultimately gives us a dynamic equation:

$$M - c_{12} (\phi_1 - \phi_2) = J_1 \frac{\partial \omega_1}{\partial t}$$

My questions are as follows:

1. Where did the masses of $$J_2$$ and $$J_3$$ go? Because we are looking for a derivative and speeds of this masses $$\omega_2$$ and $$\omega_3$$ do not explicitly depend on $$\omega_1$$, no matter how massive they are, they do not include into the equation of motion and do not affect the torque M.

2. Do I understand correctly that taking into account the influence of the moments of inertia of the remaining masses $$J_2$$ and $$J_3$$ is possible only by bringing the moments of inertia to the motor shaft $$J_1$$ (by correcting the coefficients of the square of the gear ration).

3. What tools are there in Mathematica for working with mechanical systems, equations of motion, etc.?

• I am not sure if it is a Mathematica question! Usually we prefer something with some mathematica code to work with. You can construct the differential equations and we would be interested in solving them with mathematica. Meantime have a look at this link on Lagrangian dynamics with Mathematica. Commented Jan 14, 2020 at 8:44
• @Sumit - thank you, i will try it.
– ayr
Commented Jan 14, 2020 at 9:31
• I am not clear about how the rotation comes into the problem. The diagram looks like three masses connected by springs with everything in translation. Is the problem actually one of rotation and the springs are providing a torque? Are we meant to see an axis of rotation in the above problem?
– Hugh
Commented Jan 14, 2020 at 13:09
• I just want to calculate the driving moment of the first mass using the Lagrange equation.
– ayr
Commented Jan 14, 2020 at 13:36
• The problem lies in the fact that when differentiating the Lagrangian with respect to the generalized coordinate (in our case this $\omega_1$, the components of kinetic energy that are not clearly connected with the velocity of the first mass ($\omega_2$ and $\omega_3$) disappear and it turns out that the equation of motion of the first mass does not depend on the masses of the second and subsequent masses. Look at the Lagrangian and see for yourself.
– ayr
Commented Jan 14, 2020 at 13:44

First let me derive the equations of motion.

The Lagrangian:

L = Sum[1/2 Subscript[J, i] D[Subscript[\[Phi], i][t], t]^2, {i, 3}] -
Sum[1/2 Subscript[c,
10 i + i +
1] (Subscript[\[Phi], i][t] - Subscript[\[Phi], i + 1][t])^2, {i,
2} ]


The equations of motion:

TableForm[
eqns = Table[
D[D[L, Derivative[1][q][t]], t] - D[L, q[t]] ==
Subscript[τ, q][t],
{q, {Subscript[ϕ, 1], Subscript[ϕ, 2],
Subscript[ϕ, 3]}}] /.
{Subscript[τ, Subscript[ϕ, 1]][t] -> M[t],
Subscript[τ, Subscript[ϕ, 2]][t] -> 0,
Subscript[τ, Subscript[ϕ, 3]][t] -> 0}]


A state-space representation:

asys=AffineStateSpaceModel[
AffineStateSpaceModel[
eqns, {Subscript[ϕ, 1][t], Subscript[ϕ, 2][t],
Subscript[ϕ, 3][t], Derivative[1][Subscript[ϕ, 1]][t],
Derivative[1][Subscript[ϕ, 2]][t],
Derivative[1][Subscript[ϕ, 3]][t]},
M[t], {Subscript[ϕ, 1][t], Subscript[ϕ, 2][t],
Subscript[ϕ, 3][t], Derivative[1][Subscript[ϕ, 1]][t],
Derivative[1][Subscript[ϕ, 2]][t],
Derivative[1][Subscript[ϕ, 3]][t]},
t], {Subscript[ϕ, 1][t], Subscript[ϕ, 2][t],
Subscript[ϕ, 3][t], Subscript[w, 1][t], Subscript[w, 2][t],
Subscript[w, 3][t]}]


I think in the first question you are asking if the input torque has any effect on the the second and third masses. From the 4th equation we can see that the input affects $$w_1$$. The bigger the mass the more the effort involved will be because $$J_1$$ is in the denominator. $$w_1$$ affects $$\phi_1$$. $$\phi_1$$ affects $$w_2$$, which affects $$\phi_2$$. $$\phi_2$$ affects $$w_3$$ which affects $$\phi_3$$. There is also some coupling in the sense that not only does $$w_1$$ affects $$\phi_1$$ but $$\phi_1$$ as well, etc. Also as I mentioned before the heavier the masses, the less some these influences will be.

Alternatively, you could just ask if all the positions and velocities can be adjusted using the torque on the first mass.

ControllableModelQ[%]


True

If we look a the transfer function we see that all the variables depend on all the inertia terms.

tfm = TransferFunctionModel[asys, s]


The generalized force is $$M[t]$$. From the last element of the transfer function which is that for $$\frac{w_3(s)}{M(s)}$$ we can obtain the following relationship for the generalized force.

M[s] /. Solve[Subscript[w, 3][s]/M[s] ==
SystemsModelExtract[tfm, 1, -1][s][[1, 1]], M[s]][[1]];

InverseLaplaceTransform[% /.
Subscript[w, 3][s] -> LaplaceTransform[Subscript[w, 3][t], t, s], s, t]/. _[0] -> 0


Lastly, you can see examples of such systems in AffineStateSpaceModel and related documentation.

• I don't think that's possible. The state-space is a first-order vector matrix equation where these are not separated. The standard Lagrangian form or the Kane's formulation separates the inertia and stiffness terms. Commented Jun 24, 2021 at 15:32
• vars = {Subscript[\[Phi], 1][t], Subscript[\[Phi], 2][t], Subscript[\[Phi], 3][t]}; dVars = D[vars, t]; d2Vars = D[dVars, t]; D[Subtract @@@ eqns, {d2Vars}] (* generalized mass matrix *) D[Subtract @@@ eqns, {dVars}] (* generalized damping matrix *) D[Subtract @@@ eqns, {vars}] (* generalized stiffness matrix *) -Subtract @@@ eqns /. Thread[Join[vars, dVars, d2Vars] -> 0] (* generalized forces*) Commented Jun 24, 2021 at 19:08
• Put each D[...](*...*) and the final -Subtract... in a new line. I was not able to convey that properly in the comment above. Commented Jun 25, 2021 at 12:53
• I don't quite follow what you mean by 'non-stationary', but can you obtain Lagrange's equations for such non-stationary moments of inertia? Commented Jun 27, 2021 at 0:39
• If $r$ is a gear ratio, you simply can write one angular velocity in terms of the other as $\omega _1=r \ \omega _2$ and make that substitution in the Lagrangian. It's straightforward? Commented Jun 28, 2021 at 0:13

Below is the equation of motion of the system given in OP. You need to use the variational package in Mathematica. The equation of motion is arrived at without considering the rotational inertia. And use NDsove to find the system solution.

ClearAll["Global*"];
<< VariationalMethods
Needs["DifferentialEquationsNDSolveProblems"];
Needs["DifferentialEquationsNDSolveUtilities"];
T = 0.5*m1*(D[x1[t], {t, 1}])^2 + 0.5*m2*(D[x2[t], {t, 1}])^2 +
0.5*m3*(D[x3[t], {t, 1}])^2;
V = 0.5*Subscript[C, 12]*(x1[t] - x2[t])^2 +
0.5*Subscript[C, 23]*(x2[t] - x3[t])^2;
Lg = T - V;
e1 = EulerEquations[Lg, {x1[t], x2[t], x3[t]}, {t}];
e2 = FullSimplify[e1[[1]]]
e3 = FullSimplify[e1[[2]]]
e4 = FullSimplify[e1[[3]]]

• how adequate is the result of calculating the generalized forces?
– ayr
Commented Jan 14, 2020 at 11:35
• And why is the second and third mass not affected by the equation of motion of the first mass?
– ayr
Commented Jan 14, 2020 at 11:43
• @AndrewSol you have to do the future analysis to check whether the result is adequate or not. Commented Jan 14, 2020 at 13:15
• The problem lies in the fact that when differentiating the Lagrangian with respect to the generalized coordinate (in our case this $\omega_1$, the components of kinetic energy that are not clearly connected with the velocity of the first mass ($\omega_2$ and $\omega_3$) disappear and it turns out that the equation of motion of the first mass does not depend on the masses of the second and subsequent masses. Look at the Lagrangian and see for yourself.
– ayr
Commented Jan 14, 2020 at 13:45