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 _{1} and _{2}, attached to their respective walls by two identical springs (with force constant _{2}) [1]. It is of interest to mention that in some books, this system is known as: diatomic molecules.

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 (_{1},_{1} − _{2}, and −_{2}). As a result, the potential energy reads:

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
_{1}, _{2}, we got the following ELE:

For _{1}, we have:

While for _{2}, we have:

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 _{i}p_{xi}

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 _{o}_{o}

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 _{1}(0) = −_{2}(0) = 1 and _{1}(0) = − _{2}(0) = 0.5; on the other hand, the other parameters were assumed to be _{2} = 2_{1} = 3 and _{2} = 7, see Figures 2, 3:

In this case, we considered the following two initial conditions _{1}(0) = _{2}(0) = 1 and _{1}(0) = _{2}(0) = 0.5, and the other parameters were assumed to be _{2} = 2_{1} = 3 and _{2} = 7, see Figures 4, 5:

_{2}≺≺

Finally, we considered the weak coupled oscillator case, which is of special importance. In this case, the following parameters are considered _{2} = 0.01, while _{1} = 3 and _{2} = 7, with the following two initial conditions _{1}(0) = 1, _{2}(0) = 0 and _{1}(0) = _{2}(0) = 0, see Figures 6, 7:

In this paper, the motion of the coupled oscillator system has been studied numerically using the ode45 code, and the solutions _{1}(_{2}(

Figures 2, 3 present the positions _{1}(_{2}(_{1} and _{2} against the time, respectively, for the symmetric case. The results in the same figures show that the periodicity of the oscillations has disappeared. Also, the influence on mass _{2} is clearer than that on _{1}, because it has a larger value. In addition, because _{1} and _{2} were displaced initially in opposite directions (_{1}(0) = −_{2}(0)) and then released, this is the main reason for disappearing the periodicity of the oscillations.

Figures 4, 5 present the positions _{1}(_{2}(_{1} and _{2} were displaced initially in the same direction (_{1}(0) = _{2}(0)) and then released.

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 _{1}(_{2}(_{2} = 0.01, whereas _{1} undergoes a simple harmonic oscillations, with a constant amplitude and a constant period, while mass _{2} nearly vibrates but with very small oscillations around the equilibrium position; this is due to the fact that _{2} has a larger value than _{1}.

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 _{2} does not move, because it is larger than _{1}.

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 _{1} undergoes a simple harmonic motion and not affected by mass _{2}.