Skip to content

Commit e8f475e

Browse files
Merge pull request #615 from ArnoStrouwen/example
some more examples
2 parents cc8d767 + c556d2a commit e8f475e

File tree

8 files changed

+27
-30
lines changed

8 files changed

+27
-30
lines changed

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
1212
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
1313
DiffEqDocs = "d91efeb5-c178-44a6-a2ee-51685df7c78e"
1414
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
15+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1516
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
17+
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
18+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1619
IncompleteLU = "40713840-3770-5561-ab4c-a76e7d0d7895"
1720
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
1821
JumpProblemLibrary = "faf0f6d7-8cee-47cb-b27c-1eb80cef534e"

docs/src/assets/normalized.png

-40.6 KB
Binary file not shown.
-107 KB
Binary file not shown.

docs/src/basics/faq.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ given by Dual numbers.
453453
To show this in action, let's say we want to find the Jacobian of solution
454454
of the Lotka-Volterra equation at `t=10` with respect to the parameters.
455455

456-
```julia
456+
```@example faq1
457+
using DifferentialEquations
457458
function func(du,u,p,t)
458459
du[1] = p[1] * u[1] - p[2] * u[1]*u[2]
459460
du[2] = -3 * u[2] + u[1]*u[2]
@@ -471,23 +472,16 @@ be Dual numbers whenever `p` is an array of `Dual` numbers, and we do the same
471472
for the timespan just to show what you'd do if there was parameters-dependent events.
472473
Then we can take the Jacobian via ForwardDiff.jl:
473474

474-
```julia
475+
```@example faq1
475476
using ForwardDiff
476477
ForwardDiff.jacobian(f,[1.5,1.0])
477-
478-
2×2 Array{Float64,2}:
479-
2.16056 0.188569
480-
-6.25677 -0.697978
481478
```
482479

483-
and compare it to Calculus.jl:
484-
485-
```julia
486-
Calculus.jacobian(f,[1.5,1.0],:central)
480+
and compare it to FiniteDiff.jl:
487481

488-
2×2 Array{Float64,2}:
489-
2.16056 0.188569
490-
-6.25677 -0.697978
482+
```@example faq1
483+
using FiniteDiff
484+
FiniteDiff.finite_difference_jacobian(f,[1.5,1.0])
491485
```
492486

493487
#### I get Dual number errors when I solve my ODE with Rosenbrock or SDIRK methods

docs/src/basics/plot.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ i.e. no points outside the interval will be plotted.
145145

146146
### Example
147147

148-
```julia
148+
```@example plots
149149
using DifferentialEquations, Plots
150150
function lorenz(du,u,p,t)
151151
du[1] = p[1]*(u[2]-u[1])
@@ -166,26 +166,20 @@ xyz = plot(sol, plotdensity=10000, idxs=(1,2,3))
166166
plot(plot(xyzt,xyz),plot(xy, xz, yz, layout=(1,3),w=1), layout=(2,1))
167167
```
168168

169-
![lorenz_plot](../assets/vars_plotting_example.png)
170-
171169
An example using the functions:
172170

173-
```julia
171+
```@example plots
174172
f(x,y,z) = (sqrt(x^2+y^2+z^2),x)
175173
plot(sol,idxs=(f,1,2,3))
176174
```
177175

178-
![norm_plot](../assets/normalized.png)
179-
180176
or the norm over time:
181177

182-
```julia
178+
```@example plots
183179
f(t,x,y,z) = (t,sqrt(x^2+y^2+z^2))
184180
plot(sol,idxs=(f,0,1,2,3))
185181
```
186182

187-
![normtime plot](https://user-images.githubusercontent.com/1814174/94351101-4667df80-0023-11eb-987d-aca652e32521.png)
188-
189183
## Animations
190184

191185
Using the iterator interface over the solutions, animations can also be generated

docs/src/basics/problem.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ which outputs a tuple.
6767

6868
### Examples
6969

70-
```julia
70+
```@example problem
71+
using DifferentialEquations
7172
prob = ODEProblem((u,p,t)->u,(p,t0)->p[1],(p)->(0.0,p[2]),(2.0,1.0))
73+
```
74+
```@example problem
7275
using Distributions
7376
prob = ODEProblem((u,p,t)->u,(p,t)->Normal(p,1),(0.0,1.0),1.0)
7477
```
@@ -96,7 +99,7 @@ However, you may want to modify the problem after it is created. For
9699
example, to simulate it for longer timespan. It can be done by the
97100
`remake` function:
98101

99-
```julia
102+
```@example problem
100103
prob1 = ODEProblem((u,p,t) -> u/2, 1.0, (0.0,1.0))
101104
prob2 = remake(prob1; tspan=(0.0,2.0))
102105
```

docs/src/solvers/benchmarks.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Solver Benchmarks
22

3-
Benchmarks for the solvers can be found at [benchmarks.sciml.ai](https://benchmarks.sciml.ai/stable/). The source code can be found
4-
at [SciMLBenchmarks.jl](https://github.com/SciML/SciMLBenchmarks.jl).
3+
Benchmarks for the solvers can be found at
4+
[benchmarks.sciml.ai](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/).
5+
The source code can be found at
6+
[SciMLBenchmarks.jl](https://github.com/SciML/SciMLBenchmarks.jl).
57
Many different problems are tested. However, if you would like additional problems to be benchmarked,
68
please open an issue or PR at the SciMLBenchmarks.jl repository with the code that defines the DEProblem.

docs/src/solvers/nonautonomous_linear_ode.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ Options:
6767
orthogonalization procedure (IOP) [^1]. Note that if the linear operator/jacobian is hermitian,
6868
then the Lanczos algorithm will always be used and the IOP setting is ignored.
6969

70-
```julia
70+
```@example linear_ode
71+
using DifferentialEquations
7172
_A = [2 -1;-3 -5]/5
7273
A = DiffEqArrayOperator(_A)
7374
prob = ODEProblem(A, [1.0,-1.0], (1.0, 6.0))
@@ -97,7 +98,7 @@ These methods require ``A`` is only dependent on the independent variable, i.e.
9798

9899
Example:
99100

100-
```julia
101+
```@example linear_ode
101102
function update_func(A,u,p,t)
102103
A[1,1] = cos(t)
103104
A[2,1] = sin(t)
@@ -128,7 +129,7 @@ These methods can be used when ``A`` is dependent on the state variables, i.e. `
128129

129130
Example:
130131

131-
```julia
132+
```@example linear_ode
132133
function update_func(A,u,p,t)
133134
A[1,1] = 0
134135
A[2,1] = sin(u[1])
@@ -147,7 +148,7 @@ operators can be solved using specialized adaptive algorithms, like `MagnusAdapt
147148

148149
Example:
149150

150-
```julia
151+
```@example linear_ode
151152
function update_func(A,u,p,t)
152153
A[1,1] = 0
153154
A[2,1] = 1

0 commit comments

Comments
 (0)