Skip to content

Commit e3e26fd

Browse files
Revert the classical_physics example-group split (#905)
Reverts #904. It broke the docs build on master. Splitting the shared `@example physics` block into per-topic groups gives each group its own module, so every name a group uses must be defined *within that group*. #904 fixed one escapee (`ODERKN`) but not all of them: the `double-pendulum` group also uses `g`, which is defined in an earlier block, so `makedocs` fails with ``` UndefVarError: `g` not defined in `Main.var"__atexample__named__double-pendulum"` ``` and the following block then cascades on `sol`. Restoring the single `physics` group unbreaks the build. The split is still worth doing — it is a real readability improvement — but it needs every cross-block name resolved first, which is best verified by a full docs build before merging rather than after. Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R Co-authored-by: Claude <noreply@anthropic.com>
1 parent fff0219 commit e3e26fd

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

‎docs/src/examples/classical_physics.md‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If you're getting some cold feet to jump in to DiffEq land, here are some handcr
1212

1313
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. ``λ`` is known as the decay rate, and can be related to the half-life as ``λ = \ln(2)/t_{1/2}``.
1414

15-
```@example
15+
```@example physics
1616
import OrdinaryDiffEq as ODE, Plots
1717
Plots.gr()
1818
@@ -70,7 +70,7 @@ with ``c_1``, ``c_2`` constants determined by the initial conditions such that
7070
Instead of transforming this to a system of ODEs to solve with `ODEProblem`,
7171
we can use `SecondOrderODEProblem` as follows.
7272

73-
```@example
73+
```@example physics
7474
# Simple Harmonic Oscillator Problem
7575
import OrdinaryDiffEq as ODE
7676
import OrdinaryDiffEqRKN as ODERKN # DPRKN6
@@ -135,7 +135,7 @@ of first order ODEs by employing the notation ``ω(t) = \dot{θ}``.
135135
\end{align*}
136136
```
137137

138-
```@example simple-pendulum
138+
```@example physics
139139
# Simple Pendulum Problem
140140
import OrdinaryDiffEq as ODE, Plots
141141
@@ -168,7 +168,7 @@ Plots.plot(
168168

169169
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.
170170

171-
```@example simple-pendulum
171+
```@example physics
172172
p = Plots.plot(
173173
sol, vars = (1, 2), xlims = (-9, 9), title = "Phase Space Plot",
174174
xaxis = "Angular position", yaxis = "Angular velocity", leg = false
@@ -203,7 +203,7 @@ its motion are given by the following (taken from this [Stack Overflow question]
203203
\end{pmatrix}
204204
```
205205

206-
```@example double-pendulum
206+
```@example physics
207207
#Double Pendulum Problem
208208
import OrdinaryDiffEq as ODE, Plots
209209
@@ -252,7 +252,7 @@ double_pendulum_problem = ODE.ODEProblem(double_pendulum, initial, tspan)
252252
sol = ODE.solve(double_pendulum_problem, ODE.Vern7(), abstol = 1.0e-10, dt = 0.05);
253253
```
254254

255-
```@example double-pendulum
255+
```@example physics
256256
#Obtain coordinates in Cartesian Geometry
257257
ts, ps = polar2cart(sol, l1 = L₁, l2 = L₂, dt = 0.01)
258258
Plots.plot(ps...)
@@ -267,7 +267,7 @@ This helps to understand the dynamics of interactions and is wonderfully pretty.
267267

268268
The Poincaré section in this is given by the collection of ``(β,l_β)`` when ``α=0`` and ``\frac{dα}{dt}>0``.
269269

270-
```@example double-pendulum
270+
```@example physics
271271
#Constants and setup
272272
import OrdinaryDiffEq as ODE
273273
initial2 = [0.01, 0.005, 0.01, 0.01]
@@ -310,7 +310,7 @@ function poincare_map(prob, u₀, p; callback = cb)
310310
end
311311
```
312312

313-
```@example double-pendulum
313+
```@example physics
314314
lβrange = -0.02:0.0025:0.02
315315
p = Plots.scatter(sol2, idxs = (3, 4), leg = false, markersize = 3, msw = 0)
316316
for lβ in lβrange
@@ -350,7 +350,7 @@ E = T+V = V(x,y) + \frac{1}{2} \left(\dot{x}^2+\dot{y}^2\right).
350350

351351
The total energy should conserve as this system evolves.
352352

353-
```@example henon-heiles
353+
```@example physics
354354
import OrdinaryDiffEq as ODE, Plots
355355
356356
#Setup
@@ -377,15 +377,15 @@ prob = ODE.ODEProblem(Hénon_Heiles, initial, tspan)
377377
sol = ODE.solve(prob, ODE.Vern9(), abstol = 1.0e-16, reltol = 1.0e-16);
378378
```
379379

380-
```@example henon-heiles
380+
```@example physics
381381
# Plot the orbit
382382
Plots.plot(
383383
sol, idxs = (1, 2), title = "The orbit of the Hénon-Heiles system",
384384
xaxis = "x", yaxis = "y", leg = false
385385
)
386386
```
387387

388-
```@example henon-heiles
388+
```@example physics
389389
#Optional Sanity check - what do you think this returns and why?
390390
@show sol.retcode
391391
@@ -397,7 +397,7 @@ Plots.plot(
397397
Plots.plot!(sol, idxs = (2, 4), leg = false)
398398
```
399399

400-
```@example henon-heiles
400+
```@example physics
401401
#We map the Total energies during the time intervals of the solution (sol.u here) to a new vector
402402
#pass it to the plotter a bit more conveniently
403403
energy = map(x -> E(x...), sol.u)
@@ -416,9 +416,8 @@ Plots.plot(
416416

417417
To prevent energy drift, we can instead use a symplectic integrator. We can directly define and solve the `SecondOrderODEProblem`:
418418

419-
```@example henon-heiles
419+
```@example physics
420420
import OrdinaryDiffEqSymplecticRK as ODESymp # KahanLi8
421-
import OrdinaryDiffEqRKN as ODERKN # DPRKN6
422421
function HH_acceleration!(dv, v, u, p, t)
423422
x, y = u
424423
dx, dy = dv
@@ -434,15 +433,15 @@ sol2 = ODE.solve(prob, ODESymp.KahanLi8(), dt = 1 / 10);
434433

435434
Notice that we get the same results:
436435

437-
```@example henon-heiles
436+
```@example physics
438437
# Plot the orbit
439438
Plots.plot(
440439
sol2, idxs = (3, 4), title = "The orbit of the Hénon-Heiles system",
441440
xaxis = "x", yaxis = "y", leg = false
442441
)
443442
```
444443

445-
```@example henon-heiles
444+
```@example physics
446445
Plots.plot(
447446
sol2, idxs = (3, 1), title = "Phase space for the Hénon-Heiles system",
448447
xaxis = "Position", yaxis = "Velocity"
@@ -452,7 +451,7 @@ Plots.plot!(sol2, idxs = (4, 2), leg = false)
452451

453452
but now the energy change is essentially zero:
454453

455-
```@example henon-heiles
454+
```@example physics
456455
energy = map(x -> E(x[3], x[4], x[1], x[2]), sol2.u)
457456
#We use @show here to easily spot erratic behaviour in our system by seeing if the loss in energy was too great.
458457
@show ΔE = energy[1] - energy[end]
@@ -466,7 +465,7 @@ Plots.plot(
466465

467466
And let's try to use a Runge-Kutta-Nyström solver to solve this. Note that Runge-Kutta-Nyström isn't symplectic.
468467

469-
```@example henon-heiles
468+
```@example physics
470469
sol3 = ODE.solve(prob, ODERKN.DPRKN6());
471470
energy = map(x -> E(x[3], x[4], x[1], x[2]), sol3.u)
472471
@show ΔE = energy[1] - energy[end]

0 commit comments

Comments
 (0)