# Double Pendulum Animation with Julia

**URL:** <https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [October 23, 2022, 2:18pm UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142 "2022-10-23T14:18:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [October 23, 2022, 2:18pm UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/1 "2022-10-23T14:18:14Z")

</div>

Hi all,

I saw this webpages:

[https://math24.net/double-pendulum.html](https://math24.net/double-pendulum.html)

[https://www.myphysicslab.com/pendulum/double-pendulum-en.html](https://www.myphysicslab.com/pendulum/double-pendulum-en.html)

and wonder how to create the double pendulum animation with its track in Julia?

If possible 3 pendulum will be more fun…

There is a Python code on this page:

> **[The double pendulum](https://scipython.com/blog/the-double-pendulum/)**
>
> In classical mechanics, a double pendulum is a pendulum attached to the end of another pendulum. Its equations of motion are often written using the Lagrangian formulation of mechanics and solved numerically, which is the approach taken here. The...

But, Python is silly and every update make old codes obsolete, so I want Julia to animate this…

---

<div class="post-metadata">

**Author:** ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Post date:** [October 23, 2022, 2:21pm UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/2 "2022-10-23T14:21:24Z")

</div>

[![](https://global.discourse-cdn.com/julialang/original/3X/d/6/d6694e7b573bd7d1d5338c4d6c9e865f77758aaf.jpeg "Making animations and interactive applications in Makie.jl") ](https://www.youtube.com/watch?v=L-gyDvhjzGQ)

> [@Freya\_the\_Goddess](#):
>
> But, Python is silly and every update make old codes obsolete, so I want Julia to animate this…

This will probably be problematic with Makie.jl as well.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 23, 2022, 2:27pm UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/3 "2022-10-23T14:27:56Z")

</div>

Here are four double pendulums:

[![](https://global.discourse-cdn.com/julialang/original/3X/8/2/82eccc9488edfad42be85eafd645a86642a4fd29.jpeg "Eight pendulums") ](https://www.youtube.com/watch?v=vLDpLxU2fEg)

This was written in Luxor.jl, but you can use the amazing [DynamicalSystems](https://github.com/JuliaDynamics/DynamicalSystems.jl) package for all kinds of chaotic and dynamic animations.

(Old) code [here](https://gist.github.com/cormullion/a1373e2e49e5b9912fc95cb29a912cd5) and [here](https://gist.github.com/cormullion/1fe11ac43375249939017fd16016476d).

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [October 23, 2022, 6:32pm UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/4 "2022-10-23T18:32:05Z")

</div>

There is an example in the Plots user gallery here: [Double Pendulum Problem · Plots](https://docs.juliaplots.org/stable/user_gallery/misc/Pendulum/#Double-Pendulum-Problem)

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [October 27, 2022, 7:04am UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/5 "2022-10-27T07:04:43Z")

</div>

Thank you @cormullion but @BeastyBlacksmith Pendulum is faster in moving around…

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [October 27, 2022, 8:59am UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/6 "2022-10-27T08:59:30Z")

</div>

Why I get an error on the first code when I use JupyterNotebook?

![Capture d’écran_2022-10-27_15-57-11](https://global.discourse-cdn.com/julialang/original/3X/e/b/ebea2a7637c31f7d98a4ff64101a94590b5a2314.png)

Info: Precompiling OrdinaryDiffEq [1dea7af3-3e70-54e6-95c3-0bf5283fa5ed]  
└ @ Base loading.jl:1423  
ERROR: LoadError: TypeError: in CartesianVIndex, in T, expected T\<:Tuple{Vararg{Union{VectorizationBase.NullStep, Integer}, N}}, got Type{NTuple{4, Static.StaticInt{1}}}  
Stacktrace:  
[1] _precompile_()  
@ LoopVectorization ~/.julia/packages/LoopVectorization/kVenK/src/precompile.jl:52  
[2] top-level scope  
@ ~/.julia/packages/LoopVectorization/kVenK/src/LoopVectorization.jl:116  
[3] include  
@ ./Base.jl:418 [inlined]  
[4] include\_package\_for\_output(pkg::Base.PkgId, input::String, depot\_path::Vector{String}, dl\_load\_path::Vector{String}, load\_path::Vector{String}, concrete\_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)  
@ Base ./loading.jl:1318  
[5] top-level scope  
@ none:1  
[6] eval  
@ ./boot.jl:373 [inlined]  
[7] eval(x::Expr)  
@ Base.MainInclude ./client.jl:453  
[8] top-level scope  
@ none:1  
in expression starting at /home/browni/.julia/packages/LoopVectorization/kVenK/src/LoopVectorization.jl:1  
ERROR: LoadError: Failed to precompile LoopVectorization [bdcacae8-1622-11e9-2a5c-532679323890] to /home/browni/.julia/compiled/v1.7/LoopVectorization/jl\_idB3MM.  
Stacktrace:  
[1] error(s::String)  
@ Base ./error.jl:33  
[2] compilecache(pkg::Base.PkgId, path::String, internal\_stderr::IO, internal\_stdout::IO, ignore\_loaded\_modules::Bool)  
@ Base ./loading.jl:1466  
[3] compilecache(pkg::Base.PkgId, path::String)  
@ Base ./loading.jl:1410  
[4] \_require(pkg::Base.PkgId)  
@ Base ./loading.jl:1120  
[5] require(uuidkey::Base.PkgId)  
@ Base ./loading.jl:1013  
[6] require(into::Module, mod::Symbol)  
@ Base ./loading.jl:997  
[7] include(mod::Module, \_path::String)  
@ Base ./Base.jl:418  
[8] include(x::String)  
@ RecursiveFactorization ~/.julia/packages/RecursiveFactorization/jZvER/src/RecursiveFactorization.jl:1  
[9] top-level scope  
@ ~/.julia/packages/RecursiveFactorization/jZvER/src/RecursiveFactorization.jl:3  
[10] include  
@ ./Base.jl:418 [inlined]  
[11] include\_package\_for\_output(pkg::Base.PkgId, input::String, depot\_path::Vector{String}, dl\_load\_path::Vector{String}, load\_path::Vector{String}, concrete\_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)  
@ Base ./loading.jl:1318  
[12] top-level scope  
@ none:1  
[13] eval  
@ ./boot.jl:373 [inlined]  
[14] eval(x::Expr)  
@ Base.MainInclude ./client.jl:453  
[15] top-level scope  
@ none:1  
in expression starting at /home/browni/.julia/packages/RecursiveFactorization/jZvER/src/lu.jl:1  
in expression starting at /home/browni/.julia/packages/RecursiveFactorization/jZvER/src/RecursiveFactorization.jl:1  
ERROR: LoadError: Failed to precompile RecursiveFactorization [f2c3362d-daeb-58d1-803e-2bc74f2840b4] to /home/browni/.julia/compiled/v1.7/RecursiveFactorization/jl\_50TvTX.  
Stacktrace:  
[1] error(s::String)  
@ Base ./error.jl:33  
[2] compilecache(pkg::Base.PkgId, path::String, internal\_stderr::IO, internal\_stdout::IO, ignore\_loaded\_modules::Bool)  
@ Base ./loading.jl:1466  
[3] compilecache(pkg::Base.PkgId, path::String)  
@ Base ./loading.jl:1410  
[4] \_require(pkg::Base.PkgId)  
@ Base ./loading.jl:1120  
[5] require(uuidkey::Base.PkgId)  
@ Base ./loading.jl:1013  
[6] require(into::Module, mod::Symbol)  
@ Base ./loading.jl:997  
[7] include  
@ ./Base.jl:418 [inlined]  
[8] include\_package\_for\_output(pkg::Base.PkgId, input::String, depot\_path::Vector{String}, dl\_load\_path::Vector{String}, load\_path::Vector{String}, concrete\_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)  
@ Base ./loading.jl:1318  
[9] top-level scope  
@ none:1  
[10] eval  
@ ./boot.jl:373 [inlined]  
[11] eval(x::Expr)  
@ Base.MainInclude ./client.jl:453  
[12] top-level scope  
@ none:1  
in expression starting at /home/browni/.julia/packages/DiffEqBase/S7V8q/src/DiffEqBase.jl:1  
ERROR: LoadError: Failed to precompile DiffEqBase [2b5f629d-d688-5b77-993f-72d75c75574e] to /home/browni/.julia/compiled/v1.7/DiffEqBase/jl\_vPkzY4.  
Stacktrace:  
[1] error(s::String)  
@ Base ./error.jl:33  
[2] compilecache(pkg::Base.PkgId, path::String, internal\_stderr::IO, internal\_stdout::IO, ignore\_loaded\_modules::Bool)  
@ Base ./loading.jl:1466  
[3] compilecache(pkg::Base.PkgId, path::String)  
@ Base ./loading.jl:1410  
[4] \_require(pkg::Base.PkgId)  
@ Base ./loading.jl:1120  
[5] require(uuidkey::Base.PkgId)  
@ Base ./loading.jl:1013  
[6] require(into::Module, mod::Symbol)  
@ Base ./loading.jl:997  
[7] include  
@ ./Base.jl:418 [inlined]  
[8] include\_package\_for\_output(pkg::Base.PkgId, input::String, depot\_path::Vector{String}, dl\_load\_path::Vector{String}, load\_path::Vector{String}, concrete\_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)  
@ Base ./loading.jl:1318  
[9] top-level scope  
@ none:1  
[10] eval  
@ ./boot.jl:373 [inlined]  
[11] eval(x::Expr)  
@ Base.MainInclude ./client.jl:453  
[12] top-level scope  
@ none:1  
in expression starting at /home/browni/.julia/packages/OrdinaryDiffEq/QXAKd/src/OrdinaryDiffEq.jl:1

**Failed to precompile OrdinaryDiffEq [1dea7af3-3e70-54e6-95c3-0bf5283fa5ed] to /home/browni/.julia/compiled/v1.7/OrdinaryDiffEq/jl\_kvch8x.**

**Stacktrace:**  
\*\* [1] error(s::String)\*\*  
\*\* @ Base ./error.jl:33\*\*  
\*\* [2] compilecache(pkg::Base.PkgId, path::String, internal\_stderr::IO, internal\_stdout::IO, ignore\_loaded\_modules::Bool)\*\*  
\*\* @ Base ./loading.jl:1466\*\*  
\*\* [3] compilecache(pkg::Base.PkgId, path::String)\*\*  
\*\* @ Base ./loading.jl:1410\*\*  
\*\* [4] \_require(pkg::Base.PkgId)\*\*  
\*\* @ Base ./loading.jl:1120\*\*  
\*\* [5] require(uuidkey::Base.PkgId)\*\*  
\*\* @ Base ./loading.jl:1013\*\*  
\*\* [6] require(into::Module, mod::Symbol)\*\*  
\*\* @ Base ./loading.jl:997\*\*  
\*\* [7] eval\*\*  
\*\* @ ./boot.jl:373 [inlined]\*\*

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 27, 2022, 9:17am UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/7 "2022-10-27T09:17:17Z")

</div>

> [@Freya\_the\_Goddess](#):
>
> @BeastyBlacksmith Pendulum is faster in moving around…

True. But in the description:

> The simulation uses a small term for friction, and the value of gravity is 1.62, so the pendulums behave as if they were on the moon (it’s much more relaxing than Earth gravity!:).

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [October 27, 2022, 12:52pm UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/8 "2022-10-27T12:52:10Z")

</div>

This looks like a version mismatch/ wrong compat between LoopVectorization and OrdinaryDiffEq to me. Maybe its better on julia 1.8?  
Otherwise worth to open an issue with versions specified about it.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [October 29, 2022, 7:29am UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/9 "2022-10-29T07:29:06Z")

</div>

Yes, but after see the video with Goldberg Variation, I think yours have more implicit advantages…

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [October 29, 2022, 9:22am UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/10 "2022-10-29T09:22:06Z")

</div>

It works on REPL, but not on Jupyter Notebook, thanks anyway!

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [December 11, 2023, 4:02pm UTC](https://discourse.julialang.org/t/double-pendulum-animation-with-julia/89142/11 "2023-12-11T16:02:12Z")

</div>

Since this link is popular but broken, here is the new one [Double Pendulum Problem · Plots](https://docs.juliaplots.org/stable/user_gallery/misc/double_pendulum/#Double-Pendulum-Problem)
