Skip to content

Commit 71069d4

Browse files
committed
more examples
1 parent 962837b commit 71069d4

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

docs/src/basics/Validation.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ In order to validate user-defined types and `register`ed functions, specialize `
7878
expect an object type, while two-parameter calls expect a function type as the first argument, and a vector of arguments as the
7979
second argument.
8080

81-
```julia
82-
using ModelingToolkit
81+
```@example validation2
82+
using ModelingToolkit, Unitful
8383
# Composite type parameter in registered function
8484
@parameters t
8585
D = Differential(t)
@@ -90,10 +90,10 @@ end
9090
dummycomplex(complex, scalar) = complex.f - scalar
9191
9292
c = NewType(1)
93-
MT.get_unit(x::NewType) = MT.get_unit(x.f)
94-
function MT.get_unit(op::typeof(dummycomplex),args)
95-
argunits = MT.get_unit.(args)
96-
MT.get_unit(-,args)
93+
ModelingToolkit.get_unit(x::NewType) = ModelingToolkit.get_unit(x.f)
94+
function ModelingToolkit.get_unit(op::typeof(dummycomplex),args)
95+
argunits = ModelingToolkit.get_unit.(args)
96+
ModelingToolkit.get_unit(-,args)
9797
end
9898
9999
sts = @variables a(t)=0 [unit = u"cm"]
@@ -121,14 +121,15 @@ ModelingToolkit.validate(eqs) #Returns false while displaying a warning message
121121

122122
Instead, they should be parameterized:
123123

124-
```julia
124+
```@example validation3
125125
using ModelingToolkit, Unitful
126126
@parameters τ [unit = u"ms"]
127127
@variables t [unit = u"ms"] E(t) [unit = u"kJ"] P(t) [unit = u"MW"]
128128
D = Differential(t)
129129
eqs = [D(E) ~ P - E/τ]
130130
ModelingToolkit.validate(eqs) #Returns true
131-
131+
```
132+
```@example validation3
132133
myfunc(E,τ) = E/τ
133134
eqs = [D(E) ~ P - myfunc(E,τ)]
134135
ModelingToolkit.validate(eqs) #Returns true

docs/src/examples/sparse_jacobians.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,22 @@ sparseprob = ODEProblem(sys,Pair[],(0.,11.5),jac=true,sparse=true)
6363

6464
Hard? No! How much did that help?
6565

66-
```julia
66+
```@example sparsejac
6767
using BenchmarkTools
68-
@btime solve(prob,save_everystep=false) # 51.714 s (7317 allocations: 70.12 MiB)
69-
@btime solve(sparseprob,save_everystep=false) # 2.880 s (55533 allocations: 885.09 MiB)
68+
@btime solve(prob,save_everystep=false);
69+
return nothing # hide
70+
```
71+
```@example sparsejac
72+
@btime solve(sparseprob,save_everystep=false);
73+
return nothing # hide
7074
```
7175

7276
Notice though that the analytical solution to the Jacobian can be quite expensive.
7377
Thus in some cases we may only want to get the sparsity pattern. In this case,
7478
we can simply do:
7579

76-
```julia
80+
```@example sparsejac
7781
sparsepatternprob = ODEProblem(sys,Pair[],(0.,11.5),sparse=true)
78-
@btime solve(sparsepatternprob,save_everystep=false) # 2.880 s (55533 allocations: 885.09 MiB)
82+
@btime solve(sparsepatternprob,save_everystep=false);
83+
return nothing # hide
7984
```

0 commit comments

Comments
 (0)