Problems involving vibrations (mechanical or electrical) can be reduced to problems of coupled oscillators. For this, we consider the motion of coupled oscillators system using Lagrangian method. The Lagrangian of the system was initially constructed, and then the Euler-Lagrange equations (
Keywords
- Lagrangian
- Equations of Motion
- Numerical Calculation
- ode45
- Runge-Kutta method
In classical mechanics, there are many useful techniques that can be used in solving physical systems. Newtonian mechanics is a technique based on vector concepts (
To apply Lagrangian mechanics, one has to write down the kinetic and potential energies of the system, and as a result, the Lagrangian
On the other hand, it is important to remember that all mechanical and electrical vibration problems reduce, in the case of small oscillations, to problems involving one or several coupled oscillators. Problems involving vibrations of strings, membranes, elastic solids, electrical, or acoustical can be reduced to problems of coupled oscillators; see for examples [5, 6] and references within them.
Many numerical methods have been introduced in literature to solve differential equations [7, 8, 9, 10, 11, 12]. These numerical methods are based on MATLAB, MATHEMATICA, MATCAD software and other computerized programs. For example, MATLAB contains many built-in codes that can be used in such cases (
On the other hand, many ideas have been carried out by applying MATLAB and built-in codes in solving some differential equations. For example in [15, 16, 17], the authors solved some differential equations describing physical systems by applying Lagrangian mechanics and obtaining the ELEs, which are in general differential equations that need to be solved numerically for certain initial conditions.
The outline of this paper is arranged as follows: In Section 2, the physical description of the system is presented, and the Lagrangain of the coupled oscillator is obtained. In Section 3, the numerical method used is presented. Section 4 provides the numerical solutions of the derived equations of motion for different initial conditions. The results were discussed in Section 5. We finally end the paper with conclusions.
Let us consider the system shown in Figure 1, which consists of two coupled carts of masses
Figure 1
Two coupled carts with two different masses

Assuming all springs to be massless, we aim to obtain the ELE for the system, and then we require obtaining a numerical solution for these equations under different initial conditions.
First of all, the kinetic energy (
In order to write the potential energy (
The classical Lagrangian can be immediately written as:
Our final step in this section is in obtaining the equations of motion. As such, applying our Lagrangian (eq. 3) to the following equation
For While for
Now, we aim to obtain the Hamilton’s equations of motion. The first point is introducing the following generalized momenta:
As a result, the Hamiltonian
Finally, the Hamilton’s equations can be obtained as:
In the section below, we aimed to obtain numerical solution for eqs. (9, 10) for some initial conditions.
A standard solver for ordinary differential equations (ODEs) in the simulation of MATLAB’s framework is the ode45 function. ODE45 executes the Runge-Kutta method with a variable time step for optimal computation [18, 19, 20]. A fourth-order Runge-Kutta algorithm is useful in solving non-linear differential equations, taking into consideration some given initial conditions [21]. Any problem in the following manner
With
Where
Bellow a short explanation is presented to explain how Runge-Kutta works [23].
In general, given that:
Then, one can compute in turn:
Now, everything becomes in first-order form, so the list of commands is needed in the code [24].
ODE45 is used to implement “first try” solution for most problems [25, 26]. For more details about the Runge-Kutta method, one can refer to [23, 27].
Repetition and conditional structures are used to repeat sequences in MATLAB, and from these structures are: if and if-else statements, do while, for each, while, and for loops.
In literature, there are many examples of repetition and conditional structures [23, 27].
In Section 4, we propose the numerical solution for eqs. (4 and 5) using loop structure. We consider some initial conditions, and the numerical solution for these particular conditions has been obtained.
Below, we consider some selected cases to obtain the numerical solution of eqs. (4, 5):
In this case, we considered the two initial conditions
Figure 2
The positions

Figure 3
The positions

In this case, we considered the following two initial conditions
Figure 4
The positions

Figure 5
The positions

Finally, we considered the weak coupled oscillator case, which is of special importance. In this case, the following parameters are considered
Figure 6
The positions and

Figure 7
The positions

In this paper, the motion of the coupled oscillator system has been studied numerically using the ode45 code, and the solutions
Figures 2, 3 present the positions
Figures 4, 5 present the positions
For Cases 1 and 2, it is expected that the periodicity of the oscillations will be destroyed. This is due to the fact that the spring-connected the two masses together have a larger stiffness than the two other springs.
In Figures 6, 7, the positions
Finally, one can see from the figures that if the stiffness of the spring connecting the two masses is larger than the other springs’ stiffness, then this will not allow the system to undergo simple harmonic motion. As a result, the periodicity of the motion is destroyed.
In conclusion, the periodicity of the oscillator disappeared, especially in the symmetric case. While in the antisymmetric case, the periodicity is nearly still there and not destroyed. In the weak coupled case, one can see from Figures 6, 7 that mass
After releasing the system, the displacement in the symmetric and anti-symmetric cases exceeds the initial displacement. This can be explained by the effects of springs on each other. Nonetheless, for the weak coupled oscillator, mass
Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7
