# Harmonic Motion of Pendulums¶

In this section, we will recreate an interesting experiment [Berg] involving pendulums. If we create a series of pendulums with different natural frequencies and then start them all at the same position, what we will see is that they will oscillate at different frequencies. But if we remove any energy dissipation from the system, they will eventually all “reunite” at their initial position.

In general, the period between these “reunion” events is the least common multiple of the periods of all the pendulums in the system. We can choose the lengths of the pendulums to achieve a specific period between these “reunions”.

## Pendulum Model¶

In this section, we will use arrays of components to build our subsystem model just like we did in our Spatially Distributed Heat Transfer example. But before we can create an array of pendulums, we need to first have a model of a single pendulum.

```
within ModelicaByExample.Subsystems.Pendula;
model Pendulum "A single individual pendulum"
import Modelica.Mechanics.MultiBody.Parts;
import Modelica.Mechanics.MultiBody.Joints;
parameter Modelica.SIunits.Position x;
parameter Modelica.SIunits.Mass m "Mass of mass point";
parameter Modelica.SIunits.Angle phi "Initial angle";
parameter Modelica.SIunits.Length L "String length";
parameter Modelica.SIunits.Diameter d=0.01;
Parts.Fixed ground(r={0,0,x}, animation=false)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=270, origin={0,60})));
Parts.PointMass ball(m=m, sphereDiameter=5*d)
annotation (Placement(transformation(extent={{-10,-90},{10,-70}})));
Parts.BodyCylinder string(density=0, r={0,L,0}, diameter=d)
annotation (Placement(transformation(
extent={{-10,-10},{10,10}},
rotation=90,
origin={0,-30})));
Joints.Revolute revolute(phi(fixed=true, start=phi),
cylinderDiameter=d/2, animation=false)
annotation (Placement(
transformation(
extent={{-10,-10},{10,10}},
rotation=90,
origin={0,20})));
equation
connect(string.frame_a, ball.frame_a) annotation (Line(
points={{0,-40},{0,-40},{0,-80}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(revolute.frame_b, ground.frame_b) annotation (Line(
points={{0,30},{0,40},{0,40},{0,50}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
connect(revolute.frame_a, string.frame_b) annotation (Line(
points={{0,10},{0,10},{0,-20},{0,-20}},
color={95,95,95},
thickness=0.5,
smooth=Smooth.None));
end Pendulum;
```

The components of the pendulum can be rendered as follows:

## System Model¶

Now that we have an individual pendulum model, we can build a system of pendulums. If we want a system of pendulums where the period for a complete cycle of the system is seconds, we compute the length of the pendulum as:

where is Earth’s gravitational constant, is the number of pendulums, is the period of one complete cycle of the system and is the number of oscillations of the longest pendulum over seconds.

In Modelica, we could build such a system as follows:

```
within ModelicaByExample.Subsystems.Pendula;
model System "A system of pendula"
import Modelica.Constants.g_n;
import Modelica.Constants.pi;
parameter Integer n=15 "Number of pendula";
parameter Modelica.SIunits.Position x[n] = linspace(0,(n-1)*0.05,n);
parameter Modelica.SIunits.Time T = 54;
parameter Modelica.SIunits.Time X = 30;
parameter Modelica.SIunits.Length lengths[n] = { g_n*(T/(2*pi*(X+(n-i))))^2 for i in 1:n};
parameter Modelica.SIunits.Angle phi0 = 0.5;
Pendulum pendulum[n](x=x, each m=1, each phi=phi0, L=lengths)
annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
inner Modelica.Mechanics.MultiBody.World world
annotation (Placement(transformation(extent={{-80,-60},{-60,-40}})));
end System;
```

The following declaration is particularly interesting:

```
Pendulum pendulum[n](x=x, each m=1, each phi=phi0, L=lengths)
```

Because `pendulum`

is an array of `n`

components, there will be
`n`

values for the `x`

, `m`

, `phi`

and `L`

parameters
associated with these pendulums. For example, if `n=3`

, then the
model will have 3 values for `x`

: `pendulum[1].x`

,
`pendulum[2].x`

and `pendulum[3].x`

. In the declaration of
`pendulum`

, we handle this in different ways for different
parameters. In the case of `m`

, we give each pendulum the same
value with the modification `each m=1`

. However, in the case of
`L`

(and `x`

), we supply an array of values, `L=lengths`

used to
initialize the parameters where the values in the `lengths`

array
are computed using the equation for pendulum lengths we introduced
earlier. We will give a more complete discussion on how to apply
modifications to arrays of components later in this chapter.

If we simulate this system, we get the following solution for the trajectory of each of the pendulums:

As we can see from this plot, although the pendulums oscillate at difference frequencies, their positions coincide at regular intervals. In fact, every 54 seconds they all simultaneously return to their initial positions.

This phenomenon can be more clearly visualized in three dimensions.

## Conclusion¶

In this section, we have seen how arrays of components can be used, declared and modified. In this particular case, this allows us to specify the number of pendulums in our system and then simulate them to observe the peculiar behavior observed when we choose their lengths according to the equation specified earlier.

[Berg] | Richard E. Berg, “Pendulum waves: A demonstration of wave motion using pendula” http://dx.doi.org/10.1119/1.16608 |