Skip to content

Commit c51e57a

Browse files
Merge pull request #624 from SciML/cleanup
fixup some of the example builds
2 parents d4ddd43 + d9e239d commit c51e57a

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

docs/src/examples/classical_physics.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $$f(t,u) = \frac{du}{dt}$$
1010

1111
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.
1212

13-
```julia
13+
```@example physics
1414
using OrdinaryDiffEq, Plots
1515
gr()
1616
@@ -58,7 +58,7 @@ $c_1$ is the initial position and $\omega c_2$ is the initial velocity.
5858
Instead of transforming this to a system of ODEs to solve with `ODEProblem`,
5959
we can use `SecondOrderODEProblem` as follows.
6060

61-
```julia
61+
```@example physics
6262
# Simple Harmonic Oscillator Problem
6363
using OrdinaryDiffEq, Plots
6464
@@ -112,7 +112,7 @@ $$\begin{align*}
112112
&\dot{d\theta} = - \frac{g}{L}{\sin(\theta)}
113113
\end{align*}$$
114114

115-
```julia
115+
```@example physics
116116
# Simple Pendulum Problem
117117
using OrdinaryDiffEq, Plots
118118
@@ -142,7 +142,7 @@ plot(sol,linewidth=2,title ="Simple Pendulum Problem", xaxis = "Time", yaxis = "
142142

143143
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.
144144

145-
```julia
145+
```@example physics
146146
p = plot(sol,vars = (1,2), xlims = (-9,9), title = "Phase Space Plot", xaxis = "Velocity", yaxis = "Position", leg=false)
147147
function phase_plot(prob, u0, p, tspan=2pi)
148148
_prob = ODEProblem(prob.f,u0,(0.0,tspan))
@@ -173,7 +173,7 @@ $$\frac{d}{dt}
173173
-\sin(\alpha+\beta) - 2\sin(\beta)\frac{(l_\alpha-l_\beta)l_\beta}{3-\cos2\beta} + 2\sin(2\beta)\frac{l_\alpha^2-2(1+\cos\beta)l_\alpha l_\beta + (3+2\cos\beta)l_\beta^2}{(3-\cos2\beta)^2}
174174
\end{pmatrix}$$
175175

176-
```julia
176+
```@example physics
177177
#Double Pendulum Problem
178178
using OrdinaryDiffEq, Plots
179179
@@ -205,10 +205,10 @@ end
205205
206206
#Pass to Solvers
207207
double_pendulum_problem = ODEProblem(double_pendulum, initial, tspan)
208-
sol = solve(double_pendulum_problem, Vern7(), abs_tol=1e-10, dt=0.05);
208+
sol = solve(double_pendulum_problem, Vern7(), abstol=1e-10, dt=0.05);
209209
```
210210

211-
```julia
211+
```@example physics
212212
#Obtain coordinates in Cartesian Geometry
213213
ts, ps = polar2cart(sol, l1=L₁, l2=L₂, dt=0.01)
214214
plot(ps...)
@@ -223,7 +223,7 @@ This helps to understand the dynamics of interactions and is wonderfully pretty.
223223

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

226-
```julia
226+
```@example physics
227227
#Constants and setup
228228
using OrdinaryDiffEq
229229
initial2 = [0.01, 0.005, 0.01, 0.01]
@@ -259,7 +259,7 @@ function poincare_map(prob, u₀, p; callback=cb)
259259
end
260260
```
261261

262-
```julia
262+
```@example physics
263263
lβrange = -0.02:0.0025:0.02
264264
p = scatter(sol2, vars=(3,4), leg=false, markersize = 3, msw=0)
265265
for lβ in lβrange
@@ -291,7 +291,7 @@ $$E = T+V = V(x,y)+\frac{1}{2}(\dot{x}^2+\dot{y}^2).$$
291291

292292
The total energy should conserve as this system evolves.
293293

294-
```julia
294+
```@example physics
295295
using OrdinaryDiffEq, Plots
296296
297297
#Setup
@@ -317,15 +317,15 @@ end
317317
318318
#Pass to solvers
319319
prob = ODEProblem(Hénon_Heiles, initial, tspan)
320-
sol = solve(prob, Vern9(), abs_tol=1e-16, rel_tol=1e-16);
320+
sol = solve(prob, Vern9(), abstol=1e-16, reltol=1e-16);
321321
```
322322

323-
```julia
323+
```@example physics
324324
# Plot the orbit
325325
plot(sol, vars=(1,2), title = "The orbit of the Hénon-Heiles system", xaxis = "x", yaxis = "y", leg=false)
326326
```
327327

328-
```julia
328+
```@example physics
329329
#Optional Sanity check - what do you think this returns and why?
330330
@show sol.retcode
331331
@@ -334,7 +334,7 @@ plot(sol, vars=(1,3), title = "Phase space for the Hénon-Heiles system", xaxis
334334
plot!(sol, vars=(2,4), leg = false)
335335
```
336336

337-
```julia
337+
```@example physics
338338
#We map the Total energies during the time intervals of the solution (sol.u here) to a new vector
339339
#pass it to the plotter a bit more conveniently
340340
energy = map(x->E(x...), sol.u)
@@ -350,7 +350,7 @@ plot(sol.t, energy .- energy[1], title = "Change in Energy over Time", xaxis = "
350350

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

353-
```julia
353+
```@example physics
354354
function HH_acceleration!(dv,v,u,p,t)
355355
x,y = u
356356
dx,dy = dv
@@ -365,19 +365,19 @@ sol2 = solve(prob, KahanLi8(), dt=1/10);
365365

366366
Notice that we get the same results:
367367

368-
```julia
368+
```@example physics
369369
# Plot the orbit
370370
plot(sol2, vars=(3,4), title = "The orbit of the Hénon-Heiles system", xaxis = "x", yaxis = "y", leg=false)
371371
```
372372

373-
```julia
373+
```@example physics
374374
plot(sol2, vars=(3,1), title = "Phase space for the Hénon-Heiles system", xaxis = "Position", yaxis = "Velocity")
375375
plot!(sol2, vars=(4,2), leg = false)
376376
```
377377

378378
but now the energy change is essentially zero:
379379

380-
```julia
380+
```@example physics
381381
energy = map(x->E(x[3], x[4], x[1], x[2]), sol2.u)
382382
#We use @show here to easily spot erratic behaviour in our system by seeing if the loss in energy was too great.
383383
@show ΔE = energy[1]-energy[end]
@@ -388,17 +388,12 @@ plot(sol2.t, energy .- energy[1], title = "Change in Energy over Time", xaxis =
388388

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

391-
```julia
391+
```@example physics
392392
sol3 = solve(prob, DPRKN6());
393393
energy = map(x->E(x[3], x[4], x[1], x[2]), sol3.u)
394394
@show ΔE = energy[1]-energy[end]
395395
gr()
396396
plot(sol3.t, energy .- energy[1], title = "Change in Energy over Time", xaxis = "Time in iterations", yaxis = "Change in Energy")
397397
```
398398

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.
400-
401-
```julia, echo = false, skip="notebook"
402-
using SciMLTutorials
403-
SciMLTutorials.tutorial_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
404-
```
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 `abstol=1e-16, reltol=1e-16`. Therefore, using specialized solvers to solve its particular problem is very efficient.

docs/src/examples/min_and_max.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Let's try `GN_ORIG_DIRECT_L`:
103103

104104
```@example minmax
105105
gopt = solve(optprob, NLopt.GN_ORIG_DIRECT_L())
106-
gopt2 = solve(optprob, NLopt.GN_ORIG_DIRECT_L())
106+
gopt2 = solve(optprob2, NLopt.GN_ORIG_DIRECT_L())
107107
108108
@show gopt.u, gopt2.u
109109
```

0 commit comments

Comments
 (0)