@@ -19,19 +19,27 @@ Let's take the Lorenz equation and add noise to each of the states.
19
19
To show the flexibility of ModelingToolkit,
20
20
we do not use homogeneous noise, with constant variance,
21
21
but instead use heterogeneous noise,
22
- where the magnitude of the noise scales with (0.1 times) the magnitude of each of the states:
22
+ where the magnitude of the noise scales with (0.3 times) the magnitude of each of the states:
23
23
24
24
``` math
25
25
\begin{aligned}
26
- dx &= (\sigma (y-x))dt &+ 0.1xdB \\
27
- dy &= (x(\rho-z) - y)dt &+ 0.1ydB \\
28
- dz &= (xy - \beta z)dt &+ 0.1zdB \\
26
+ \frac{dx}{dt} &= (\sigma (y-x)) &+ 0.1x\frac{dB}{dt} \\
27
+ \frac{dy}{dt} &= (x(\rho-z) - y) &+ 0.1y\frac{dB}{dt} \\
28
+ \frac{dz}{dt} &= (xy - \beta z) &+ 0.1z\frac{dB}{dt} \\
29
29
\end{aligned}
30
30
```
31
31
32
32
Where $B$, is standard Brownian motion, also called the
33
33
[ Wiener process] ( https://en.wikipedia.org/wiki/Wiener_process ) .
34
- In ModelingToolkit this can be done by ` @brownian ` variables.
34
+ We use notation similar to the
35
+ [ Langevin equation] ( https://en.wikipedia.org/wiki/Stochastic_differential_equation#Use_in_physics ) ,
36
+ often used in physics.
37
+ By "multiplying" the equations by $dt$, the notation used in
38
+ [ probability theory] ( https://en.wikipedia.org/wiki/Stochastic_differential_equation#Use_in_probability_and_mathematical_finance )
39
+ can be recovered.
40
+
41
+ We use this Langevin-like notation because it allows us to extend MTK modeling capacity from ODEs to SDEs,
42
+ using only a single new concept, ` @brownian ` variables, which represent $\frac{dB}{dt}$ in the above equation.
35
43
36
44
``` @example SDE
37
45
using ModelingToolkit, StochasticDiffEq
@@ -41,9 +49,9 @@ using Plots
41
49
@parameters σ=10.0 ρ=2.33 β=26.0
42
50
@variables x(t)=5.0 y(t)=5.0 z(t)=1.0
43
51
@brownian B
44
- eqs = [D(x) ~ σ * (y - x) + 0.1B * x ,
45
- D(y) ~ x * (ρ - z) - y + 0.1B * y ,
46
- D(z) ~ x * y - β * z + 0.1B * z ]
52
+ eqs = [D(x) ~ σ * (y - x) + 0.3x * B ,
53
+ D(y) ~ x * (ρ - z) - y + 0.3y * B ,
54
+ D(z) ~ x * y - β * z + 0.3z * B ]
47
55
48
56
@mtkbuild de = System(eqs, t)
49
57
```
@@ -58,22 +66,29 @@ We continue by solving and plotting the SDE.
58
66
59
67
``` @example SDE
60
68
prob = SDEProblem(de, [], (0.0, 100.0), [])
61
- sol = solve(prob, LambaEulerHeun ())
69
+ sol = solve(prob, SRIW1 ())
62
70
plot(sol, idxs = [(1, 2, 3)])
63
71
```
64
72
65
73
The noise present in all 3 equations is correlated, as can be seen on the below figure.
66
- If you want uncorrelated noise for each equation,
67
- multiple ` @brownian ` variables have to be declared.
74
+ The figure also shows the multiplicative nature of the noise.
75
+ Because states ` x ` and ` y ` generally take on larger values,
76
+ the noise also takes on a more pronounced effect on these states compared to the state ` z ` .
68
77
69
78
``` @example SDE
70
- @brownian Bx By Bz
79
+ plot(sol)
71
80
```
72
81
73
- The figure also shows the multiplicative nature of the noise.
74
- Because states ` x ` and ` y ` generally take on larger values,
75
- the noise also takes on a more pronounced effect on these states compared to the state ` z ` .
82
+ If you want uncorrelated noise for each equation,
83
+ multiple ` @brownian ` variables have to be declared.
76
84
77
85
``` @example SDE
86
+ @brownian Bx By Bz
87
+ eqs = [D(x) ~ σ * (y - x) + 0.3x * Bx,
88
+ D(y) ~ x * (ρ - z) - y + 0.3y * By,
89
+ D(z) ~ x * y - β * z + 0.3z * Bz]
90
+ @mtkbuild de = System(eqs, t)
91
+ prob = SDEProblem(de, [], (0.0, 100.0), [])
92
+ sol = solve(prob, SRIW1())
78
93
plot(sol)
79
94
```
0 commit comments