Loading [MathJax]/jax/output/HTML-CSS/jax.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

3.5.1: The Nonlinear Pendulum

( \newcommand{\kernel}{\mathrm{null}\,}\)

NOW WE WILL INVESTIGATE THE USE OF NUMERCIAL METHODS fOr SOLVing the nonlinear pendulum problem.

Example 3.5.1.1: Nonlinear Pendulum

Solve

¨θ=gLsinθ,θ(0)=θ0,ω(0)=0,t[0,8],

using Euler’s Method. Use the parameter values of m=0.005 kg, L=0.500 m, and g=9.8 m/s2.

This is a second order differential equation. As describe later, we can write this differential equation as a system of two first order differential equations,

\boldsymbol{\begin{equation}\begin{aligned} \dot{\theta} &=\omega, \\[4pt] \dot{\omega} &=-\dfrac{g}{L} \sin \theta . \end{aligned}\label{3.26}}

Defining the vector

Θ(t)=(θ(t)ω(t))

we can write the first order system as

dΘdt=F(t,Θ),Θ(0)=(θ00)

where

F(t,Θ)=(ω(t)gLsinθ(t))

This allows us to use the the methods we have discussed on this first order equation for Θ(t).

For example, Euler’s Method for this system becomes

Θi+1=Θi+1+hF(ti,Θi)

With Θ0=Θ(0).

We can write this scheme in component form as

(θi+1ωi+1)=(θiωi)+h(ωigLsinθi)

or

θi+1=θi+hωiωi+1=ωihgLsinθi

starting with θ0=θ0 and ω0=0.

The MATLAB code that can be used to implement this scheme takes the form.

g=9.8;

L=0.5;

m=0.005;

a=0;

b=8;

N=500;

h=(b-a)/N;

% Initial Condition

t(1)=0;

theta(1)=pi/6;

omega(1)=0;

% Euler’s Method for

i=2:N+1

omega(i)=omega(i-1)-g/L*h*sin(theta(i-1));

theta(i)=theta(i-1)+h*omega(i-1);

t(i)=t(i-1)+h;

end

clipboard_e73fb9d2d6ee2fee569793826956e245b.png
Figure 3.5.1.1: Solution for the nonlinear pendulum problem using Euler’s Method on t[0,8] with N=500.

In Figure 3.5.1.1 we plot the solution for a starting position of 300 with N=500. Notice that the amplitude of oscillation is increasing, contrary to our experience. So, we increase N and see if that helps. In Figure 3.5.1.2 we show the results for N= 500, 1000, and 2000 points, or h=0.016, 0.008, and 0.004, respectively. We note that the amplitude is not increasing as much.

The problem with the solution is that Euler’s Method is not an energy conserving method. As conservation of energy is important in physics, we would like to be able to seek problems which conserve energy. Such schemes used to solve oscillatory problems in classical mechanics are called symplectic integrators. A simple example is the Euler-Cromer, or semi-implicit Euler Method. We only need to make a small modification of Euler’s Method. Namely, in the second equation of the method we use the updated value of the dependent variable as computed in the first line.

clipboard_eb66939348b45cc679fdb4b9eca95aaea.png
Figure 3.5.1.2: Solution for the nonlinear pendulum problem using Euler’s Method on t[0,8] with N=500,1000,2000.

Let’s write the Euler scheme as

ωi+1=ωihgLsinθiθi+1=θi+hωi

Then, we replace ωi in the second line by ωi+1 to obtain the new scheme

ωi+1=ωihgLsinθiθi+1=θi+hωi+1

The MATLAB code is easily changed as shown below.

g=9.8;

L=0.5;

m=0.005;

a=0;

b=8;

N=500;

h=(b-a)/N;

% Initial Condition

t(1)=0;

theta(1)=pi/6;

omega(1)=0;

% Euler-Cromer Method

for i=2:N+1

omega(i)=omega(i-1)-g/L*h*sin(theta(i-1));

theta(i)=theta(i-1)+h*omega(i);

t(i)=t(i-1)+h;

end

We then run the new scheme for N=500 and compare this with what we obtained before. The results are shown in Figure 3.5.1.3. We see that the oscillation amplitude seems to be under control. However, the best test would be to investigate if the energy is conserved.

Recall that the total mechanical energy for a pendulum consists of the kinetic and gravitational potential energies,

E=12mv2+mgh

For the pendulum the tangential velocity is given by v=Lω and the height of the pendulum mass from the lowest point of the swing is h=L(1cosθ). Therefore, in terms of the dynamical variables, we have

E=12mL2ω2+mgL(1cosθ)

We can compute the energy at each time step in the numerical simulation. In MATLAB it is easy to do using

E = 1/2*m*L^2*omega.^2+m*g*L*(1-cos(theta));

after implementing the scheme. In other programming environments one needs to loop through the times steps and compute the energy along the way. In Figure 3.5.1.4 we shown the results for Euler’s Method for N= 500,1000,2000 and the Euler-Cromer Method for N=500. It is clear that the Euler-Cromer Method does a much better job at maintaining energy conservation.

clipboard_e235cd86b95e868b03d9192d2a20975ca.png
Figure 3.5.1.3: Solution for the nonlinear pendulum problem comparing Euler’s Method and the Euler-Cromer Method on t[0,8] with N=500.
clipboard_ed1ec42ac8025a2cf17f4472601ecd81b.png
Figure 3.5.1.4: Total energy for the nonlinear pendulum problem.

This page titled 3.5.1: The Nonlinear Pendulum is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Russell Herman via source content that was edited to the style and standards of the LibreTexts platform.

  • Was this article helpful?

Support Center

How can we help?