Skip to content

Commit 9ca2616

Browse files
Merge pull request #3758 from hersle/fixpert
Fix plot in perturbation example
2 parents 7ab2feb + 4a1ea71 commit 9ca2616

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

docs/src/examples/perturbation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ eqs_pert = taylor_coeff(eq_pert, ϵ, 0:2)
9393
We solve and plot it as in the previous example, and compare the solution with $ϵ=0.1$ to the exact solution $x(t, ϵ) = e^{-ϵ t} \sin(\sqrt{(1-ϵ^2)}\,t) / \sqrt{1-ϵ^2}$ of the unperturbed equation:
9494

9595
```@example perturbation
96-
u0 = Dict([unknowns(sys) .=> 0.0; D(y[0]) => 1.0]) # nonzero initial velocity
96+
u0 = [y[0] => 0.0, y[1] => 0.0, y[2] => 0.0, D(y[0]) => 1.0, D(y[1]) => 0.0, D(y[2]) => 0.0] # nonzero initial velocity
9797
prob = ODEProblem(sys, u0, (0.0, 50.0))
9898
sol = solve(prob)
9999
plot(sol, idxs = substitute(x_series, ϵ => 0.1); label = "Perturbative (ϵ=0.1)")
100100
101101
x_exact(t, ϵ) = exp(-ϵ * t) * sin(√(1 - ϵ^2) * t) / √(1 - ϵ^2)
102+
@assert isapprox(sol(π/2; idxs = substitute(x_series, ϵ => 0.1)), x_exact(π/2, 0.1); atol = 1e-2) # compare around 1st peak # hide
102103
plot!(sol.t, x_exact.(sol.t, 0.1); label = "Exact (ϵ=0.1)")
103104
```
104105

0 commit comments

Comments
 (0)