Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler...

20
Numerical Methods and the Dampened, Driven Pendulum Matthew Epland Department of Physics, Duke University (Dated: July 26, 2016) The behavior of a dampened, driven simple pendulum was investigated numerically via the Euler– Cromer O ( t) 2 ) and Rung–Kutta methods O ( t) 4 ) . The pendulum’s resonance curves, non- linear behavior, and chaotic properties were studied for a variety of driving frequencies, amplitudes, and initial conditions. Adapted from an assignment completed for PHYS 566 Computational Physics with Professor Bass. I. INTRODUCTION Damped, driven pendulums are a rich second order system for study, exhibiting many interesting behaviors such as resonance, nonlinear equations, and chaos. Furthermore they are a good system to model computationally as analytical solutions can be derived for comparison, in the limit of the linear, small angle approximation. Here a damped, driven simple pendulum was simulated with the Euler–Cromer and Rung–Kutta methods. By varying parameters of the system resonance, nonlinear effects and chaos were studied in turn, as well as the differences between the two simulation methods themselves. II. THEORY The equation of motion of a damped, driven pendulum (1) for small angles 1 is a second order linear equation. As written all of the constants are positive real numbers. It is helpful to rewrite (1) as (2) where ω 2 0 = g/l and F (t) is the external driving force. d 2 θ dt 2 = - g l θ - 2γ dt + α D sin (Ω D t) (1) ¨ θ +2γ ˙ θ + ω 2 0 θ = F (t) F (t)= α D sin (Ω D t) (2) The solution to (2) can be broken into two parts, the solution of the associated homogeneous equation where F (t) = 0, and any particular solution of (2). To begin with we will solve the homogeneous equation by assuming a solution of the form θ (t) e rt , which is indeed a solution provided that r is a root of the characteristic equation (3). Using the quadratic formula we find the two roots to be r ± (4), thereby specifying the homogeneous solution 2 (5). r 2 +2γr + ω 2 0 =0 (3) r ± = -γ ± q γ 2 - ω 2 0 (4) θ (t) Homogeneous = ( Ae r+t + Be r-t if γ 6= ω 0 (A + Bt) e -γt if γ = ω 0 (5) It is easy to see from (4) that Re (r ± ) < 0 for all γ and ω 0 , therefore the homogeneous solution (5) always decays away to nothing; it is a transient solution 3 . As we are primary interested in the steady state behavior of the pendulum we therefore need only be concerned with the particular solution from here on out. 1 Where sin (θ) θ + O ( θ 2 ) 2 If γ = ω 0 , and therefore r + = r - , we need to include a multiplicative factor of t on one of the solutions so that they are linearly independent. 3 The homogeneous solutions importance in this case lies in it’s ability to match the initial conditions of the pendulum, regardless of what the driving force is doing. For our pendulum the initial conditions are θ (t = 0) = θ 0 (t = 0) = 0

Transcript of Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler...

Page 1: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

Numerical Methods and the Dampened, Driven Pendulum

Matthew EplandDepartment of Physics, Duke University

(Dated: July 26, 2016)

The behavior of a dampened, driven simple pendulum was investigated numerically via the Euler–Cromer O

((∆t)2

)and Rung–Kutta methods O

((∆t)4

). The pendulum’s resonance curves, non-

linear behavior, and chaotic properties were studied for a variety of driving frequencies, amplitudes,and initial conditions. Adapted from an assignment completed for PHYS 566 Computational Physicswith Professor Bass.

I. INTRODUCTION

Damped, driven pendulums are a rich second order system for study, exhibiting many interesting behaviors suchas resonance, nonlinear equations, and chaos. Furthermore they are a good system to model computationally asanalytical solutions can be derived for comparison, in the limit of the linear, small angle approximation. Herea damped, driven simple pendulum was simulated with the Euler–Cromer and Rung–Kutta methods. By varyingparameters of the system resonance, nonlinear effects and chaos were studied in turn, as well as the differences betweenthe two simulation methods themselves.

II. THEORY

The equation of motion of a damped, driven pendulum (1) for small angles1 is a second order linear equation. Aswritten all of the constants are positive real numbers. It is helpful to rewrite (1) as (2) where ω2

0 = g/l and F (t) isthe external driving force.

d2θ

dt2= −g

lθ − 2γ

dt+ αD sin (ΩDt) (1)

θ + 2γθ + ω20θ = F (t)

F (t) = αD sin (ΩDt)(2)

The solution to (2) can be broken into two parts, the solution of the associated homogeneous equation whereF (t) = 0, and any particular solution of (2). To begin with we will solve the homogeneous equation by assuming asolution of the form θ (t) ∼ ert, which is indeed a solution provided that r is a root of the characteristic equation (3).Using the quadratic formula we find the two roots to be r± (4), thereby specifying the homogeneous solution2 (5).

r2 + 2γr + ω20 = 0 (3)

r± = −γ ±√

γ2 − ω20 (4)

θ (t)Homogeneous =

Aer+t +Ber−t if γ 6= ω0

(A+Bt) e−γt if γ = ω0(5)

It is easy to see from (4) that Re (r±) < 0 for all γ and ω0, therefore the homogeneous solution (5) always decaysaway to nothing; it is a transient solution3. As we are primary interested in the steady state behavior of the pendulumwe therefore need only be concerned with the particular solution from here on out.

1 Where sin (θ) ≈ θ +O(θ2

)2 If γ = ω0, and therefore r+ = r−, we need to include a multiplicative factor of t on one of the solutions so that they are linearlyindependent.

3 The homogeneous solutions importance in this case lies in it’s ability to match the initial conditions of the pendulum, regardless of whatthe driving force is doing. For our pendulum the initial conditions are θ (t = 0) = θ0, ω (t = 0) = 0

Page 2: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

2

We can find a particular, or steady state, solution (6) that works by trial and error. Plugging (6) into (2) withF (t) = αD sin (ΩDt) results in (7).

θ (t)Particular = θP sin (ΩDt− φ) (6)

αD

θPsin (ΩDt) =

(ω20 − Ω2

D

)sin (ΩDt− φ) + 2γΩD cos (ΩDt− φ) (7)

While (7) may look rather messy, it is possible to extract the steady state amplitude θP (ΩD) and phase φ (ΩD). Oneof the simpler, but less rigorous4, ways to do so is by making use of the trigonometric identity (8) with α = ΩDt− φand β = φ. Rearranging (7) into (9), we can identify (10) term by term.

sin (α+ β) = sin (α) cos (β) + cos (α) sin (β) (8)

sin (α+ β) = sin (α)

(θPαD

(ω20 − Ω2

D

))+ cos (α)

(2γΩDθP

αD

)(9)

cos (φ) =θPαD

(ω20 − Ω2

D

)sin (φ) =

2γΩDθPαD

(10)

Now that sin (φ) and cos (φ) are known, θP (ΩD) and φ (ΩD) (11 and 12) can be found from the sum of their squaresand their ratio, respectively.

θP (ΩD) =αD√

(ω20 − Ω2

D)2+ 4γ2Ω2

D

(11)

φ (ΩD) = arctan

(2γΩD

ω20 − Ω2

D

)(12)

A. Resonance

As our pendulum is a driven oscillator we can expect it to exhibit resonant behavior at some driving frequency, ΩRes.To find ΩRes analytically we can employ the usual maximization method5 of solving for where the first derivative iszero (13).

0 =dθPdΩD

∣∣∣∣ΩD=ΩRes

= −αD

2

((ω20 − Ω2

Res

)2+ 4γ2Ω2

Res

)−3/2(− 4

(ω20 − Ω2

Res

)ΩRes + 8γ2ΩRes

)(13)

ΩRes =√

ω20 − 2γ2 (14)

Lastly, note that ΩRes of (14) solves (13) when ω0 6= γ. If ω0 ≈ γ the (· · · )−3/2 term diverges and we would need to setγ = ω0 at the beginning of the problem and redo the derivation. Here we choose ω0 = 1.0 s−1 6= γ = 0.25 s−1 → ΩRes =0.93541 [rad/s], so this is not an issue.

4 Since α and β are clearly correlated via their shared φ dependence, the term by term identification argument is somewhat suspect.5 Of course the resulting extrema could be a minimum of θP (ΩD), but in this case it is indeed a maximum as later figures show.

Page 3: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

3

B. Euler–Cromer

The default Euler method is a simple technique for solving differential equations numerically, however its solutionsusually do not conserve energy but tend to increase in total energy over time. We can remedy this by switching tothe Euler–Cromer method, also known as the semi-implicit Euler method6, by modifying the Euler method to useωn+1 instead of ωn when computing θn+1, see (15, 16).

dt= f (t, θ; ω)

dt=

d2θ

dt2= g (t, ω; θ) (15)

θn+1 = θn + f(tn, θn; ωn+1

)∆t ωn+1 = ωn + g (tn, ωn; θn)∆t (16)

tn = t0 + n∆t = n∆t (17)

For our pendulum we have:

f (t, θ; ω) = ω g (t, ω; θ) = −ω20θ − 2γω + αD sin (ΩDt) (18)

C. Runge–Kutta

The Euler and Euler–Cromer methods work by sampling the differential equation once at the beginning of eachtime step, which when worked out gives them a final error of O

((∆t)

2 ). As such, an easy way to improve on the

Euler method is to sample the differential equation more than once per time step. The family of numerical solutionsof this type are called Runge–Kutta methods, of which the Euler method is the simplest member. In addition to theEuler–Cromer method we will be using The Runge–Kutta method, or RK4, which samples the differential equationfour times per time step. The four samples are used in a weighted average in place of f (t) and g (t) in the Eulermethod, compare (15, 16) to (19, 20). By averaging over four samples per time step the RK4 method decreases the

error to O((∆t)

4 ), quite a nice improvement for relatively little effort.7 For our pendulum f (t) and g (t) remain the

same as before (18).

θn+1 = θn +1

6(k1 + 2k2 + 2k3 + k4)∆t ωn+1 = ωn +

1

6(l1 + 2l2 + 2l3 + l4)∆t (19)

k1 = f (tn, θn; ωn)

k2 = f (tn +∆t/2, θn + k1∆t/2; ωn + l1∆t/2)

k3 = f (tn +∆t/2, θn + k2∆t/2; ωn + l2∆t/2)

k4 = f (tn +∆t, θn + k3∆t; ωn + l3∆t)

l1 = g (tn, ωn; θn)

l2 = g (tn +∆t/2, ωn + l1∆t/2; θn + k1∆t/2)

l3 = g (tn +∆t/2, ωn + l2∆t/2; θn + k2∆t/2)

l4 = g (tn +∆t, ωn + l3∆t; θn + k3∆t)

(20)

6 The name semi-implicit comes from the fact that n + 1 data in the form of ωn+1 is being used to compute θn+1. Also note that likethe unmodified Euler method, the Euler–Cromer method is still only a O

((∆t)2

)method.

7 We could also alter the RK4 method to be an implicit method like the Euler–Cromer method, but will not do so here to avoid additionalcomplexity.

Page 4: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

4

III. RESULTS

A. Simulation Methods

We will begin by comparing the results of the two simulation methods, Euler–Cromer and RK4, by looking atplots of θ (t), ω (t), and energy versus time. As you can see in Figures 1 through 4, both methods produced virtuallyidentical results for this pendulum. For the energy plots note that we do not expect total energy to be conserved,even at steady state, because FDriving and FDampening are external forces that continually doing work on the system.If we turn them off, setting αD = 0.0, γ = 0.0, we do have energy conservation, see Section IVB.

0 20 40 60 80 100 120 140 160t [s]

0.4

0.2

0.0

0.2

0.4

θ(t) [

rad]

Vary Sim. Method

Euler-Cromer

RK4

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

αD = 0.2 [rad/s2], ΩD = 0.74833 [rad/s]

FIG. 1: θ (t) for the Euler–Cromer and RK4 methods.

0 20 40 60 80 100 120 140 160t [s]

0.3

0.2

0.1

0.0

0.1

0.2

0.3

ω( t

) [ra

d/s

]

Vary Sim. Method

Euler-Cromer

RK4

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

αD = 0.2 [rad/s2], ΩD = 0.74833 [rad/s]

FIG. 2: ω (t) for the Euler–Cromer and RK4 methods.

Page 5: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

5

0 10 20 30 40 50 60 70t [s]

0

2

4

6

8

E/m

ass

[J/m

ass

]

Energy: Euler-Cromer

T

V

E=T+V

θ0 = 10.0

Sim. Method = Euler-CromerLinearity = LinearαD = 0.2 [rad/s2], ΩD = 0.88864 [rad/s]

FIG. 3: Kinetic, potential and total energy when using the Euler–Cromer method.

0 10 20 30 40 50 60 70t [s]

0

2

4

6

8

E/m

ass

[J/m

ass

]

Energy: RK4

T

V

E=T+V

θ0 = 10.0

Sim. Method = RK4Linearity = LinearαD = 0.2 [rad/s2], ΩD = 0.88864 [rad/s]

FIG. 4: Kinetic, potential and total energy when using the RK4 method.

Page 6: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

6

B. Resonance

For the rest of the results we will use the RK4 method to simulate the pendulum. By fitting the steady state θ (t)curve with a sinusoid we are able to extract θP (ΩD) and φ (ΩD) for many different value of ΩD about ΩRes, seeFigures 5 and 6. The analysis code was written to automatically perform the fit after waiting a preset number ofdriving force periods to ensure the steady state had been reached. Supporting plots were made for each ΩD tested toconfirm the fit was good and only included the steady state wave, see Figures 7 and 8 for one example at ΩD = 1.6688[rad/s].

The θP (ΩD) resonance peak itself was fit twice, to a Gaussian with an offset and to the form of the analyticalcurve derived earlier (11). As you can see in Figure 5 the analytical “Spectrum Fit” matched the simulation dataand the theory curve extremely well, all the fit parameters match to five decimal places. This validates our analyticalderivation in Section II, or the numerical simulation code, depending on which you decide to trust more initially.On the other hand, the Gaussian fit was very poor; which is not surprising considering the analytical curve is notsymmetric. The chief reason for fitting with a Gaussian is to compare the Full Width at Half Maximum8 to γ. TheGaussian fit’s FWHM was ≈ 4γ suggesting that γ2 sets the width of the resonance peak, though this is better seenanalytically in (11) as well as in Section IVC.

1.0 0.5 0.0 0.5 1.0 1.5 2.0 2.5ΩD [rad/s]

0.0

0.1

0.2

0.3

0.4

0.5

θ P S

im. Fi

t V

alu

es

[rad]

θP Sim. Fit Values vs ΩD

ΩRes.Theory = 0.935 [rad/s]

θP(ΩD) Spectrum Fit

θP(ΩD) Theory

θP(ΩD) Gaussian Fit

θP Sim. Fit Values

Spectrum Fit Parameters:ω0Actual = 1.00, ω0Fit = 1.00000 [rad/s]γActual = 0.25, γFit = 0.25000 [s−1]αDActual = 0.20, αDFit = 0.20000 [rad/s2]

Gaussian Fit Parameters:µ= 0.8422 [rad/s], σ= 0.3582 [rad/s]Amplitude = 0.2716 [rad]Offset = 0.1082 [rad]FWHM = 1.1105µ/ΩRes.Theory = 0.900, FWHM/γ = 4.442

θ0 = 0.0

Sim. Method = RK4Linearity = Linear

FIG. 5: θP (ΩD) resonance curve and fits.

8 With the offset included, the FWHM = 2σ√

−2 ln (2−1(1− (offset/amplitude))), which reduces to the usual FWHM if offset = 0.

Page 7: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

7

The φ (ΩD) resonance peak was fit with the analytical curve (12). Again there was very good agreement betweenthe simulation data, the analytical fit curve, and the analytical theory.

1.0 0.5 0.0 0.5 1.0 1.5 2.0 2.5ΩD [rad/s]

0.5

0.0

0.5

1.0

1.5

2.0

2.5

3.0

φ S

im. Fi

t V

alu

es

[rad]

φ Sim. Fit Values vs ΩD

ΩRes.Theory = 0.935 [rad/s]

φ(ΩD) Spectrum Fit

φ(ΩD) Theory

φ Sim. Fit Values

Spectrum Fit Parameters:ω0Actual = 1.00, ω0Fit = 1.00000 [rad/s]γActual = 0.25, γFit = 0.25000 [s−1]

θ0 = 0.0

Sim. Method = RK4Linearity = Linear

FIG. 6: φ (ΩD) resonance curve and fit.

Page 8: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

8

0 10 20 30 40 50 60t [s]

0.3

0.2

0.1

0.0

0.1

0.2

0.3

θ [r

ad]

θ(t), ΩD = 1.6688 [rad/s] = 1.78 ΩRes.Theory

Unfitted θ(t) Fitted θ(t) Fit Begins Fit θ(t)Particular

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

θPTheory = 0.10151 [rad], θPFit = 0.10151 [rad]ΩD = 1.66878 [rad/s], ΩDFit = 1.66878 [rad/s]φTheory = 2.70429 [rad], φFit = 2.70427 [rad]

FIG. 7: θ (t) at ΩD = 1.6688 [rad/s], full view. Note how the fit is performed on data well into the steady stateregion.

45 50 55 60 65 70t [s]

0.3

0.2

0.1

0.0

0.1

0.2

0.3

θ [r

ad]

θ(t), ΩD = 1.6688 [rad/s] = 1.78 ΩRes.Theory

Unfitted θ(t) Fitted θ(t) Fit Begins Fit θ(t)Particular

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

θPTheory = 0.10151 [rad], θPFit = 0.10151 [rad]ΩD = 1.66878 [rad/s], ΩDFit = 1.66878 [rad/s]φTheory = 2.70429 [rad], φFit = 2.70427 [rad]

FIG. 8: θ (t) at ΩD = 1.6688 [rad/s], fit region. The sinusoidal fit typically matched the theory predictions to all theshown decimal places. This ΩD plot was chosen to be included in particular to illustrate that the data was really

being fit – you can see a difference in the last decimal place of the φ values.

Page 9: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

9

C. Nonlinear Effects

As we are running a numerical simulation there is no problem in abandoning the small angle approximation andhaving the restoring force go as −ω2

0 sin (θ). We only need to change g (t, ω; θ) to (21) and the Euler–Cromer andRK4 methods will run just as easily as before. This is in sharp contrast to the difficultly of attempting to redo theanalytical derivation.

g (t, ω; θ)nonlinear = −ω20 sin (θ)− 2γω + αD sin (ΩDt) (21)

When the driving force amplitude is small, αD = 0.2 [rad/s2], the pendulum does not move far from θ = 0. Inthis case we expect the small angle approximation hold, and indeed there are no real differences between the linearand nonlinear simulations, see Figures 9 and 10. However, when the driving force is increased, αD = 1.2 [rad/s2],it drives the pendulum up to higher θ’s, breaking the small angle approximation. In this case significant deviationsoccur between the linear and nonlinear simulations, see Figures 11 and 12. The nonlinear simulation is the correctmethod to use here.

Page 10: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

10

0 20 40 60 80 100 120 140 160t [s]

0.4

0.2

0.0

0.2

0.4

θ(t) [

rad]

Vary Linearity: αD = 0.2 [rad/s2]

Linear

Nonlinear

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

αD = 0.2 [rad/s2], ΩD = 0.74833 [rad/s]

FIG. 9: θ (t) for the linear and nonlinear restoring force, αD = 0.2 [rad/s2].

0 20 40 60 80 100 120 140 160t [s]

0.3

0.2

0.1

0.0

0.1

0.2

0.3

ω( t

) [ra

d/s

]

Vary Linearity: αD = 0.2 [rad/s2]

Linear

Nonlinear

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

αD = 0.2 [rad/s2], ΩD = 0.74833 [rad/s]

FIG. 10: ω (t) for the linear and nonlinear restoring force, αD = 0.2 [rad/s2].

Page 11: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

11

0 20 40 60 80 100 120 140 160t [s]

4

2

0

2

4

θ(t) [

rad]

Vary Linearity: αD = 1.2 [rad/s2]

Linear

Nonlinear

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

αD = 1.2 [rad/s2], ΩD = 0.74833 [rad/s]

FIG. 11: θ (t) for the linear and nonlinear restoring force, αD = 1.2 [rad/s2].

0 20 40 60 80 100 120 140 160t [s]

3

2

1

0

1

2

3

ω( t

) [ra

d/s

]

Vary Linearity: αD = 1.2 [rad/s2]

Linear

Nonlinear

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

αD = 1.2 [rad/s2], ΩD = 0.74833 [rad/s]

FIG. 12: ω (t) for the linear and nonlinear restoring force, αD = 1.2 [rad/s2].

Page 12: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

12

D. Chaos and Lyapunov Exponents

When working through the theory of the linear pendulum we showed that the initial conditions only affectedthe transient solution which decayed away exponentially to leave the steady state sinusoid. As such two differentpendulums, or systems, with slightly different initial conditions are expected to converge over time. However if weforce the pendulum to behave nonlinearly, by increasing αD or θ0 till the small angle approximation breaks down,we must use −ω2

0 sin (θ) as the restoring force and can no longer rely on the linear theory. Now if two nonlinearsystems are setup with very slightly different initial conditions they may no longer converge, but could insteaddiverge, even exponentially diverge, over time9. Systems displaying such exponential divergence for small changes ininitial conditions are classified as chaotic and can be quantitatively described by a Lyapunov Exponent λ, defined in(22) where |∆θ (t)| is the difference in position10 between the systems at time t and |∆θ0| is the difference in initialposition.

∣∣∆θ (t)∣∣ = ∣∣∆θ0

∣∣eλt (22)

While any combination of initial conditions can be altered to produce chaotic behavior, we will only be changingθ0 itself by 0.001 ≤ ∆θ0 ≤ 0.005 [rad/s] in our simulation. The resulting |∆θ (t)| values are so small we instead plotln (|∆θ (t) /∆θ0|) which also helps by linearizing the data. To find λ we then fit the linearized plot with (23)11 overthe region in time where the systems are exponentially diverging.

ln

(∣∣∣∣∆θ (t)

∆θ0

∣∣∣∣)

= cFit + λFitt (23)

By repeating the simulation and fit multiple times for small changes in ∆θ0 we can average the λFit’s and comeup with an estimate of λ of the system. Three different driving force amplitudes where considered in turn, αD = 0.2,0.5, and 1.2 [rad/s2]. The first two where small enough that the system behaved linearly and did not exhibit chaos,indeed the λFit’s < 0 verified the transient solution’s exponential decay, see Figures 13–16.

For αD = 1.2 [rad/s2], previously looked at in Section III C, the system was again nonlinear and showed chaoticbehavior, see Figure 17. The mean λFit was found to be 0.1251 [s−1], although the structure in Figure 18 shows thatthe mean alone may not adequately describe the situation. For the purposes of this work we will leave it here, thoughindividuals interested in the particulars of system itself could characterize this behavior further.

9 Each system is still fully deterministic once the initial conditions are specified. Chaotic system are just extremely sensitive to the initialconditions

10 In general we can look at the difference in phase space, but position is fine here.11 An offset c is included so the fit is not overly constrained, even though c should ideally be 0 as we have already divided by ∆θ0.

Page 13: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

13

0 25 50 75 100 125 150t [s]

40

35

30

25

20

15

10

5

0

ln(|∆

θ(t)/∆θ 0|)

[rad]

Linearized |∆θ(t)|: ∆θ0 = 2.00E-03 [rad]

Fitted ln(|∆θ(t)/∆θ0|)Unfitted ln(|∆θ(t)/∆θ0|)Fit Bounds

Fit

Fit Function: ln(|∆θ(t)/∆θ0|) = c+λt

λFit = -0.25093 [s−1]cFit = -0.62762

θ0 = 0.0, αD = 0.2 [rad/s]Fit Range: 20.0 t 75.0 [s]Sim. Method = RK4

FIG. 13:∣∣∆θ (t)

∣∣ curve and linear fit, αD = 0.2 [rad/s2], nonchaotic regime.

0.000 0.001 0.002 0.003 0.004 0.005∆θ0 [rad]

0.255

0.250

0.245

0.240

0.235

0.230

0.225

0.220

λFit [

s−1]

Fit Values for: αD = 0.2 [rad/s2], θ0 = 0.0, RK4

0.636

0.634

0.632

0.630

0.628

0.626

0.624

0.622

0.620λFit

Mean λFit = -0.2509 [s−1]

cFit

Mean cFit = -0.6278

FIG. 14: λFit curve and mean, αD = 0.2 [rad/s2], nonchaotic regime.

Page 14: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

14

0 25 50 75 100 125 150t [s]

35

30

25

20

15

10

5

0

ln(|∆

θ(t)/∆θ 0|)

[rad]

Linearized |∆θ(t)|: ∆θ0 = 2.00E-03 [rad]

Fitted ln(|∆θ(t)/∆θ0|)Unfitted ln(|∆θ(t)/∆θ0|)Fit Bounds

Fit

Fit Function: ln(|∆θ(t)/∆θ0|) = c+λt

λFit = -0.25105 [s−1]cFit = -0.63550

θ0 = 0.0, αD = 0.5 [rad/s]Fit Range: 20.0 t 75.0 [s]Sim. Method = RK4

FIG. 15:∣∣∆θ (t)

∣∣ curve and linear fit, αD = 0.5 [rad/s2], nonchaotic regime.

0.000 0.001 0.002 0.003 0.004 0.005∆θ0 [rad]

0.255

0.250

0.245

0.240

0.235

0.230

0.225

0.220

λFit [

s−1]

Fit Values for: αD = 0.5 [rad/s2], θ0 = 0.0, RK4

0.644

0.642

0.640

0.638

0.636

0.634

0.632

0.630

0.628λFit

Mean λFit = -0.2511 [s−1]

cFit

Mean cFit = -0.6352

FIG. 16: λFit curve and mean, αD = 0.5 [rad/s2], nonchaotic regime.

Page 15: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

15

0 25 50 75 100 125 150t [s]

15

10

5

0

5

10

ln(|∆

θ(t)/∆θ 0|)

[rad]

Linearized |∆θ(t)|: ∆θ0 = 2.00E-03 [rad]

Fitted ln(|∆θ(t)/∆θ0|)Unfitted ln(|∆θ(t)/∆θ0|)Fit Bounds

Fit

Fit Function: ln(|∆θ(t)/∆θ0|) = c+λt

λFit = 0.13296 [s−1]cFit = -2.89273

θ0 = 0.0, αD = 1.2 [rad/s]Fit Range: 20.0 t 75.0 [s]Sim. Method = RK4

FIG. 17:∣∣∆θ (t)

∣∣ curve and linear fit, αD = 1.2 [rad/s2], chaotic regime.

0.000 0.001 0.002 0.003 0.004 0.005∆θ0 [rad]

0.08

0.10

0.12

0.14

0.16

λFit [

s−1]

Fit Values for: αD = 1.2 [rad/s2], θ0 = 0.0, RK4

3.5

3.0

2.5

2.0

1.5

1.0λFit

Mean λFit = 0.1251 [s−1]

cFit

Mean cFit = -2.5913

FIG. 18: λFit curve and mean, αD = 1.2 [rad/s2], chaotic regime.

Page 16: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

16

IV. EXTRA MATERIAL

A. Nonlinear Resonance Curves

Since the simulation code is already written we can also see what the nonlinear restoring force does to the resonancecurves, Figures 22 and 23. For this resonance sweep αD was left at 1.2 [rad/s2] while θ0 was increased to 45 to makethe pendulum as nonlinear as possible. Note that the theory curves are still using the linear, small angle approximationout of necessity, but this is fine as it allows us to see how far the resonance curves diverge from the linear theory.With these parameters the pendulum exhibits very interesting behavior; alternating between high and low frequencybeats at low driving frequencies, Figure 19, periodically swinging over the top at intermediate driving frequencies,Figure 20, and behaving somewhat linear at high driving frequencies, Figure 21.

1000 1100 1200 1300 1400 1500 1600t [s]

6

4

2

0

2

4

6

θ [r

ad]

θ(t), ΩD = 0.0798 [rad/s] = 0.09 ΩRes.Theory

Unfitted θ(t) Fitted θ(t) Fit Begins Fit θ(t)Particular

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

θPTheory = 1.20672 [rad], θPFit = 0.80549 [rad]ΩD = 0.07982 [rad/s], ΩDFit = 0.07953 [rad/s]φTheory = 0.04015 [rad], φFit = -0.58307 [rad]

FIG. 19: Nonlinear θ (t) at low ΩD = 0.0798 [rad/s].

180 200 220 240 260 280t [s]

6

4

2

0

2

4

6

θ [r

ad]

θ(t), ΩD = 0.4465 [rad/s] = 0.48 ΩRes.Theory

Unfitted θ(t) Fitted θ(t) Fit Begins Fit θ(t)Particular

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

θPTheory = 1.44373 [rad], θPFit = 0.32321 [rad]ΩD = 0.44650 [rad/s], ΩDFit = 0.46179 [rad/s]φTheory = 0.27194 [rad], φFit = 4.08114 [rad]

FIG. 20: Nonlinear θ (t) at intermediate ΩD = 0.4465 [rad/s].

Page 17: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

17

70 80 90 100t [s]

2

1

0

1

2

θ [r

ad]

θ(t), ΩD = 1.2410 [rad/s] = 1.33 ΩRes.Theory

Unfitted θ(t) Fitted θ(t) Fit Begins Fit θ(t)Particular

1.5

1.0

0.5

0.0

0.5

1.0

1.5

FD

rivin

g /αD

θPTheory = 1.45881 [rad], θPFit = 1.25793 [rad]ΩD = 1.24098 [rad/s], ΩDFit = 1.24099 [rad/s]φTheory = 2.28698 [rad], φFit = 2.43425 [rad]

FIG. 21: Nonlinear θ (t) at high ΩD = 1.2410 [rad/s].

1.0 0.5 0.0 0.5 1.0 1.5 2.0 2.5ΩD [rad/s]

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

θ P S

im. Fi

t V

alu

es

[rad]

θP Sim. Fit Values vs ΩD

ΩRes.Theory = 0.935 [rad/s]

θP(ΩD) Spectrum Fit

θP(ΩD) Theory

θP(ΩD) Gaussian Fit

θP Sim. Fit Values

Spectrum Fit Parameters:ω0Actual = 1.00, ω0Fit = 0.95993 [rad/s]γActual = 0.25, γFit = 0.18723 [s−1]αDActual = 1.20, αDFit = 0.82712 [rad/s2]

Gaussian Fit Parameters:µ= 0.8844 [rad/s], σ= 0.2100 [rad/s]Amplitude = 1.6427 [rad]Offset = 0.6981 [rad]FWHM = 0.6631µ/ΩRes.Theory = 0.945, FWHM/γ = 2.653

θ0 = 45.0

Sim. Method = RK4Linearity = Nonlinear

FIG. 22: θP (ΩD) resonance curve and fits, nonlinear restoring force. Points at low to intermediate ΩD should bedisregarded as the sinusoidal fits are clearly non–convergent there.

Page 18: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

18

1.0 0.5 0.0 0.5 1.0 1.5 2.0 2.5ΩD [rad/s]

6

4

2

0

2

4

6

8

φ S

im. Fi

t V

alu

es

[rad]

φ Sim. Fit Values vs ΩD

ΩRes.Theory = 0.935 [rad/s]

φ(ΩD) Spectrum Fit

φ(ΩD) Theory

φ Sim. Fit Values

Spectrum Fit Parameters:ω0Actual = 1.00, ω0Fit = 0.37840 [rad/s]γActual = 0.25, γFit = 0.44468 [s−1]

θ0 = 45.0

Sim. Method = RK4Linearity = Nonlinear

FIG. 23: φ (ΩD) resonance curve and fit, nonlinear restoring force. Points at low to intermediate ΩD should bedisregarded as the sinusoidal fits are clearly non–convergent there.

Page 19: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

19

B. Energy Conservation

0 20 40 60 80t [s]

0

2

4

6

8

10

12

14

16

E/m

ass

[J/m

ass

]

Energy: Euler-Cromer

T

V

E=T+V

θ0 = 30.0

Sim. Method = Euler-CromerLinearity = NonlinearαD = 0.0 [rad/s2], ΩD = 0.88864 [rad/s]

FIG. 24: Free pendulum, αD = 0.0, γ = 0.0: Kinetic, potential and total energy when using the Euler–Cromermethod.

0 20 40 60 80t [s]

0

2

4

6

8

10

12

14

16

E/m

ass

[J/m

ass

]

Energy: RK4

T

V

E=T+V

θ0 = 30.0

Sim. Method = RK4Linearity = NonlinearαD = 0.0 [rad/s2], ΩD = 0.88864 [rad/s]

FIG. 25: Free pendulum, αD = 0.0, γ = 0.0: Kinetic, potential and total energy when using the RK4 method.

Page 20: Numerical Methods and the Dampened, Driven Pendulummbe9/data_science/pendulum/nume… · Euler method is to sample the di erential equation more than once per time step. The family

20

C. Analytical Resonance Curves

θP Analytical_Resonance_Spectrum

In[30]:= Clear["Global`*"]

In[31]:= thetaP[gamma_, Omega_] := ((1 - Omega^2)^2 + 4 gamma^2 Omega^2)^-0.5;

In[32]:= gamma = 0.25;p1 = Plot[thetaP[gamma, Omega], Omega, 0, 2, PlotStyle → Blue];

In[34]:= gamma = 0.5;p2 = Plot[thetaP[gamma, Omega], Omega, 0, 2, PlotStyle → Green];

In[36]:= gamma = 1;p3 = Plot[thetaP[gamma, Omega], Omega, 0, 2, PlotStyle → Cyan];

In[38]:= Show[p1, p2, p3, AxesLabel → "ΩP[rad/s]", "θP"]

Out[38]=

0.5 1.0 1.5 2.0ΩP [rad/s]

0.5

1.0

1.5

2.0

θP