[Pendulums, Time & Motion][Numerical Methods]Jan 3

Euler's Method: Simulating the Future

How Euler’s method lets us simulate the world, one tiny step at a time.

Euler’s Method: Simulating the Future

Act 1: Leonhard Euler (1707 - 1783)

While Galileo, Newton and others before them handed us the keys to motion, and mathematical foundations like Calculus discovered around this period [1] helped in developing elegant and powerful solutions for simple systems like pendulums, most of the systems are not that simple. Any attempt to solve complex systems, such as the movement of car wheels when the engine forces the transmission to move them using analytical calculus, would be like using nail clippers to excavate a mile-long tunnel.

Calculus quickly turns into a wild jungle.

Born in 1707 in Switzerland, Euler was a maths wizard—no less "The King of Mathematics" [2]. He is hailed as such, and many people are intimidated by the title. He worked in Berlin and St. Petersburg, went blind later in life (but kept calculating in his head!) [3], and left us with so many formulas that people still rediscover his works.

Euler could say about many current works that are still relevant, Been there, done that. Just think about it—over 250 years later, and his works are still relevant.

But first, let’s remember where we left off with the pendulum. Newton’s laws gave us this classic (and slightly intimidating) equation:

d2Θdt2+glsin(Θ)=0\frac{d^2 \Theta}{dt^2} + \frac{g}{l} \sin(\Theta) = 0

This little beauty tells us how a pendulum swings, but it’s a non-linear beast—tricky to solve analytically exactly unless you’re a fan of elliptic functions [4].

Fun fact: elliptic functions pop up in the proof of Fermat's Last Theorem [5]. A theorem that Euler could not prove, well add Gauss, Lagrange, Cauchy and several other greats to that list. So let us not step into that jungle yet. For small swings, however, we can cheat a bit and say sin(Θ)Θ\sin(\Theta) \approx \Theta as we have seen before.

But what if we want to handle the real thing sin(Θ)\sin(\Theta) and not approximate, we better let the computers do these kind of work and tell them how to though algorithms?

Act 2: Numerical Algorithm: Euler's Method

We break out the numerical integration toolkit [6]. Instead of leaping straight to the future, we tiptoe there one tiny step at a time.

Let’s talk about what we want from the computer at the end to learn or predict/simulate a swinging pendulum. Our equation from before,

d2Θdt2+glsin(Θ)=0\frac{d^2 \Theta}{dt^2} + \frac{g}{l} \sin(\Theta) = 0

is a second-order differential equation. That means, to predict the future, we need to know not just where the pendulum starts (its initial angle θ0\theta_0), but also how fast it’s moving at the start (its initial angular velocity ω0\omega_0). Two pieces of information for two derivatives—fair’s fair!

Now we need some mathematical gymnastics before we can easily use Euler's method, because Euler's method by definition works with first-order equations. Let's move to the next Act.

Act 3: State Space .𖥔 ݁ ˖ִ🛸༄˖°.

Without actually going too deep into this here [7], I will convince you that for the equation of motion for the pendulum, which is a second-derivative in time, you need two time-dependent variables to track the system and here we can say that all we need are:

  1. Angular-Position (θ(t)\theta(t))
  2. Velocity (ω(t)\omega(t))

Now let us morph the equation for pendulum motion below and we start numbering the equations now:

d2θdt2+glsin(θ)=0(1)\frac{d^2 \theta}{dt^2} + \frac{g}{l} \sin(\theta) = 0 \tag{1}

into these two equations:

dθ(t)dt=ω(t)(2) \frac{d \theta(t)}{dt} = \omega(t) \tag{2} dω(t)dt=glsin(θ(t))(3) \frac{d \omega(t)}{dt} = -\frac{g}{l} \sin(\theta(t)) \tag{3}

Take some time with it and you will find that equations 2 and 3 together are equivalent to equation 1. Now we have written the pendulum equation that exclusively depends on the two state-space variables we defined earlier and their time derivatives. We are now ready for Euler's method.

Before we proceed, let's look a little closer. When you inspect equations (2) and (3), try plugging in the initial values of the state-space variables at time t=0t = 0. We have:

  1. Initial condition - 2, -> initial velocity is zero
dθ(t=0)dt=ω(t=0)=0(4) \frac{d \theta(t=0)}{dt} = \omega(t=0) = 0 \tag{4}
  1. Initial condition - 1 -> initial position is θmax\theta_{max}
dω(t=0)dt=glsin(θ(t=0))=glsin(θmax)(5) \frac{d \omega(t=0)}{dt} = -\frac{g}{l} \sin(\theta(t=0)) = -\frac{g}{l} \sin(\theta_{max}) \tag{5}

Now try to plug in future times—you cannot get the values because you don't have the information. This is where the cleverly devised information-chaining method introduced by Euler helps us march through time and track complete information about the system. We will see in the next section, finally we are so close to the predictable nature we so desire.

Act 4: Time-Marching

Let us say y(t)y(t) is function of time like position of the "Bob". Then, Euler's method says [8]:

y(tn+1)=y(tn)+hy(tn,y(tn))(6) y(t_{n+1}) = y(t_{n}) + h \cdot y'(t_{n}, y(t_{n})) \tag{6}

where hh is the step size for marching in time. If you want to predict the system at 0.1 seconds after t=0t = 0, then h=0.1h = 0.1 seconds.

Now for θ(t)\theta(t) that is the position of the "Bob" we can write,

θ(tn+1)=θ(tn)+hθ(tn,θ(tn))(7) \theta(t_{n+1}) = \theta(t_{n}) + h \cdot \theta'(t_{n}, \theta(t_{n})) \tag{7}

and for velocity we can write, just like equation 6 as,

ω(tn+1)=ω(tn)+hω(tn,ω(tn))(8) \omega(t_{n+1}) = \omega(t_{n}) + h \cdot \omega'(t_{n}, \omega(t_{n})) \tag{8}

Now, it should be apparent to a keen eye that the way we wrote equations 2 and 3 has derivatives on the left-hand side. These can be directly used to replace the derivative terms in equations 7 and 8, making them specific to the pendulum system. Right now, equations 7 and 8 are just general expressions for Euler's method written in terms of two different state-space variables—they contain no information about the pendulum. Let's fix that:

θ(tn+1)=θ(tn)+hω(tn)(8) \theta(t_{n+1}) = \theta(t_{n}) + h \omega(t_{n}) \tag{8}

and for velocity we can write, just like equation 6 as,

ω(tn+1)=ω(tn)+h(glsin(θ(tn)))(9) \omega(t_{n+1}) = \omega(t_{n}) + h *(-\frac{g}{l} \sin(\theta(t_{n}))) \tag{9}

With equations 8 and 9 above, you can start from t=0t = 0, where all the quantities on the right are known, and estimate the state space at t=0.1t = 0.1 seconds, and so on.

Predictibility is mine! And the Clockwork of the world is achieved.!

Act 5: Demystify with Some Hand Calculations

Let's use equations 8 and 9 and march through time for a few steps to demonstrate how this works before asking the computer to scale up the calculations!

Suppose:

  • g=9.8g = 9.8 m/s², L=1L = 1 m
  • dt=0.1dt = 0.1 s
  • Initial angle θ0=0.2\theta_0 = 0.2 rad (about 11°)
  • Initial angular velocity ω0=0\omega_0 = 0

Step 1 (at t0=0t_0 = 0):

Using Equation (9): ω(tn+1)=ω(tn)+h(glsin(θ(tn)))\omega(t_{n+1}) = \omega(t_n) + h \left(-\frac{g}{l} \sin(\theta(t_n))\right)

ω1=0+0.1(9.81sin(0.2))=0+0.1(1.948)=0.1948\omega_1 = 0 + 0.1 \cdot \left(-\frac{9.8}{1} \sin(0.2)\right) = 0 + 0.1 \cdot (-1.948) = -0.1948

Using Equation (8): θ(tn+1)=θ(tn)+hω(tn)\theta(t_{n+1}) = \theta(t_n) + h \omega(t_n)

θ1=0.2+0.10=0.2\theta_1 = 0.2 + 0.1 \cdot 0 = 0.2

Time advances: t1=0+0.1=0.1t_1 = 0 + 0.1 = 0.1 s

Step 2 (at t1=0.1t_1 = 0.1):

Using Equation (9) with updated θ1=0.2\theta_1 = 0.2:

ω2=0.1948+0.1(9.81sin(0.2))=0.1948+0.1(1.948)=0.3896\omega_2 = -0.1948 + 0.1 \cdot \left(-\frac{9.8}{1} \sin(0.2)\right) = -0.1948 + 0.1 \cdot (-1.948) = -0.3896

Using Equation (8) with current ω1=0.1948\omega_1 = -0.1948:

θ2=0.2+0.1(0.1948)=0.18052\theta_2 = 0.2 + 0.1 \cdot (-0.1948) = 0.18052

Time advances: t2=0.1+0.1=0.2t_2 = 0.1 + 0.1 = 0.2 s

Step 3 (at t2=0.2t_2 = 0.2):

Using Equation (9) with updated θ2=0.18052\theta_2 = 0.18052:

ω3=0.3896+0.1(9.81sin(0.18052))=0.3896+0.1(1.761)=0.5657\omega_3 = -0.3896 + 0.1 \cdot \left(-\frac{9.8}{1} \sin(0.18052)\right) = -0.3896 + 0.1 \cdot (-1.761) = -0.5657

Using Equation (8) with current ω2=0.3896\omega_2 = -0.3896:

θ3=0.18052+0.1(0.3896)=0.14156\theta_3 = 0.18052 + 0.1 \cdot (-0.3896) = 0.14156

Time advances: t3=0.2+0.1=0.3t_3 = 0.2 + 0.1 = 0.3 s


Act 6: Finale - Analytical vs Euler Simulation

Below, you can pit the true (analytical, small angle) solution against the Euler approximation. Crank up the time step (dt) or the initial angle and watch how Euler’s method starts to wander off the path. It’s a bit like watching a friend try to follow directions after one too many cups of coffee:

Pendulum: Euler vs Analytical

Current Euler angle: 11.46°   |  Analytical angle: 11.46°   |  Time: 0.00s

Black: Euler’s method  |  Blue: Analytical (small angle)

Try increasing dt or the initial angle to see how Euler’s method diverges from the true solution.

Do you think predictability is still fully within our grasp? You can see that after some time, we start predicting the wrong state of the system. Are there any saviors now?


Quiz: Euler’s Method Limitations

Euler’s Method Quiz

What is the main idea behind Euler's method for solving differential equations?
If you make the time step (dt) too large in Euler's method, what happens?
Do you think Euler is always over predicting then angle value?

References

  1. Newton, I. & Leibniz, G.W. The priority dispute is well-documented in: Hall, A.R. (1980). Philosophers at War: The Quarrel between Newton and Leibniz. Cambridge University Press. ISBN 978-0-521-22732-2.

  2. Dunham, W. (1999). Euler: The Master of Us All. Mathematical Association of America. ISBN 978-0-88385-328-3. MAA Publication

  3. Calinger, R. (2016). Leonhard Euler: Mathematical Genius in the Enlightenment. Princeton University Press. pp. 456-470, on Euler's blindness. ISBN 978-0-691-11927-4.

  4. Lawden, D.F. (1989). Elliptic Functions and Applications. Springer-Verlag. Chapter 5: "The Simple Pendulum." ISBN 978-0-387-96965-5.

  5. Wiles, A. (1995). "Modular elliptic curves and Fermat's Last Theorem." Annals of Mathematics, 141(3), pp. 443-551. JSTOR

  6. Euler, L. (1768). Institutionum calculi integralis, Vol. 1. St. Petersburg Imperial Academy. The foundational work where numerical methods for differential equations appear. Euler Archive

  7. Arnold, V.I. (1989). Mathematical Methods of Classical Mechanics, 2nd ed. Springer-Verlag. Chapter 1: "Experimental Facts" (introduces phase space). ISBN 978-0-387-96890-0.

  8. Euler, L. (1768). Institutionum calculi integralis, Vol. 1, Section 650. The explicit forward difference method: yn+1=yn+hf(yn,tn)y_{n+1} = y_n + h \cdot f(y_n, t_n). Euler Archive

The Newton's ForceALL CHAPTERSThe Price of Speed: Runge-Kutta vs Euler