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: docs/src/examples/classical_physics.md
+20-25Lines changed: 20 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ $$f(t,u) = \frac{du}{dt}$$
10
10
11
11
The Radioactive decay problem is the first order linear ODE problem of an exponential with a negative coefficient, which represents the half-life of the process in question. Should the coefficient be positive, this would represent a population growth equation.
12
12
13
-
```julia
13
+
```@example physics
14
14
using OrdinaryDiffEq, Plots
15
15
gr()
16
16
@@ -58,7 +58,7 @@ $c_1$ is the initial position and $\omega c_2$ is the initial velocity.
58
58
Instead of transforming this to a system of ODEs to solve with `ODEProblem`,
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.
144
144
145
-
```julia
145
+
```@example physics
146
146
p = plot(sol,vars = (1,2), xlims = (-9,9), title = "Phase Space Plot", xaxis = "Velocity", yaxis = "Position", leg=false)
plot(sol2, vars=(3,4), title = "The orbit of the Hénon-Heiles system", xaxis = "x", yaxis = "y", leg=false)
371
371
```
372
372
373
-
```julia
373
+
```@example physics
374
374
plot(sol2, vars=(3,1), title = "Phase space for the Hénon-Heiles system", xaxis = "Position", yaxis = "Velocity")
375
375
plot!(sol2, vars=(4,2), leg = false)
376
376
```
377
377
378
378
but now the energy change is essentially zero:
379
379
380
-
```julia
380
+
```@example physics
381
381
energy = map(x->E(x[3], x[4], x[1], x[2]), sol2.u)
382
382
#We use @show here to easily spot erratic behaviour in our system by seeing if the loss in energy was too great.
383
383
@show ΔE = energy[1]-energy[end]
@@ -388,17 +388,12 @@ plot(sol2.t, energy .- energy[1], title = "Change in Energy over Time", xaxis =
388
388
389
389
And let's try to use a Runge-Kutta-Nyström solver to solve this. Note that Runge-Kutta-Nyström isn't symplectic.
390
390
391
-
```julia
391
+
```@example physics
392
392
sol3 = solve(prob, DPRKN6());
393
393
energy = map(x->E(x[3], x[4], x[1], x[2]), sol3.u)
394
394
@show ΔE = energy[1]-energy[end]
395
395
gr()
396
396
plot(sol3.t, energy .- energy[1], title = "Change in Energy over Time", xaxis = "Time in iterations", yaxis = "Change in Energy")
397
397
```
398
398
399
-
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.
Note that we are using the `DPRKN6` sovler at `reltol=1e-3` (the default), yet it has a smaller energy variation than `Vern9` at `abstol=1e-16, reltol=1e-16`. Therefore, using specialized solvers to solve its particular problem is very efficient.
0 commit comments