You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: tutorials/models/01-classical_physics.jmd
+112-43
Original file line number
Diff line number
Diff line change
@@ -5,9 +5,9 @@ author: Yingbo Ma, Chris Rackauckas
5
5
6
6
If you're getting some cold feet to jump in to DiffEq land, here are some handcrafted differential equations mini problems to hold your hand along the beginning of your journey.
7
7
8
-
## Radioactive Decay of Carbon-14
8
+
## First order linear ODE
9
9
10
-
#### First order linear ODE
10
+
#### Radioactive Decay of Carbon-14
11
11
12
12
$$f(t,u) = \frac{du}{dt}$$
13
13
@@ -36,9 +36,67 @@ plot(sol,linewidth=2,title ="Carbon-14 half-life", xaxis = "Time in thousands of
Note that the order of the variables (and initial conditions) is `dx`, `x`.
95
+
Thus, if we want the first series to be `x`, we have to flip the order with `vars=[2,1]`.
96
+
97
+
## Second Order Non-linear ODE
98
+
99
+
#### Simple Pendulum
42
100
43
101
We will start by solving the pendulum problem. In the physics class, we often solve this problem by small angle approximation, i.e. $ sin(\theta) \approx \theta$, because otherwise, we get an elliptic integral which doesn't have an analytic solution. The linearized form is
44
102
@@ -48,6 +106,17 @@ But we have numerical ODE solvers! Why not solve the *real* pendulum?
48
106
49
107
$$\ddot{\theta} + \frac{g}{L}{\sin(\theta)} = 0$$
50
108
109
+
Notice that now we have a second order ODE.
110
+
In order to use the same method as above, we nee to transform it into a system
111
+
of first order ODEs by employing the notation $d\theta = \dot{\theta}$.
So now we know that behaviour of the position versus time. However, it will be useful to us to look at the phase space of the pendulum, i.e., and representation of all possible states of the system in question (the pendulum) by looking at its velocity and position. Phase space analysis is ubiquitous in the analysis of dynamical systems, and thus we will provide a few facilities for it.
@@ -93,9 +162,21 @@ end
93
162
plot(p,xlims = (-9,9))
94
163
```
95
164
96
-
## Simple Harmonic Oscillator
165
+
#### Double Pendulum
97
166
98
-
### Double Pendulum
167
+
A more complicated example is given by the double pendulum. The equations governing
168
+
its motion are given by the following (taken from this [StackOverflow question](https://mathematica.stackexchange.com/questions/40122/help-to-plot-poincar%C3%A9-section-for-double-pendulum))
The Poincaré section is a contour plot of a higher-dimensional phase space diagram. It helps to understand the dynamic interactions and is wonderfully pretty.
144
-
145
-
The following equation came from [StackOverflow question](https://mathematica.stackexchange.com/questions/40122/help-to-plot-poincar%C3%A9-section-for-double-pendulum)
plot(sol2.t, energy, title = "Change in Energy over Time", xaxis = "Time in iterations", yaxis = "Change in Energy")
393
+
plot(sol2.t, energy .- energy[1], title = "Change in Energy over Time", xaxis = "Time in iterations", yaxis = "Change in Energy")
325
394
```
326
395
327
-
It's so close to zero it breaks GR! And let's try to use a Runge-Kutta-Nyström solver to solve this. Note that Runge-Kutta-Nyström isn't symplectic.
396
+
And let's try to use a Runge-Kutta-Nyström solver to solve this. Note that Runge-Kutta-Nyström isn't symplectic.
328
397
329
398
```julia
330
399
sol3 = solve(prob, DPRKN6());
331
400
energy = map(x->E(x[3], x[4], x[1], x[2]), sol3.u)
332
401
@show ΔE = energy[1]-energy[end]
333
402
gr()
334
-
plot(sol3.t, energy, title = "Change in Energy over Time", xaxis = "Time in iterations", yaxis = "Change in Energy")
403
+
plot(sol3.t, energy .- energy[1], title = "Change in Energy over Time", xaxis = "Time in iterations", yaxis = "Change in Energy")
335
404
```
336
405
337
406
Note that we are using the `DPRKN6` sovler at `reltol=1e-3` (the default), yet it has a smaller energy variation than `Vern9` at `abs_tol=1e-16, rel_tol=1e-16`. Therefore, using specialized solvers to solve its particular problem is very efficient.
0 commit comments