Skip to content

Commit a457b3f

Browse files
authored
Merge pull request #1795 from SciML/YingboMa-patch-1
Update plot and format README
2 parents 5048309 + 98739ea commit a457b3f

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

README.md

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,27 @@ using DifferentialEquations, ModelingToolkit
4444
@variables x(t) y(t) z(t)
4545
D = Differential(t)
4646

47-
eqs = [D(D(x)) ~ σ*(y-x),
48-
D(y) ~ x*-z)-y,
49-
D(z) ~ x*y - β*z]
47+
eqs = [D(D(x)) ~ σ * (y - x),
48+
D(y) ~ x *- z) - y,
49+
D(z) ~ x * y - β * z]
5050

5151
@named sys = ODESystem(eqs)
5252
sys = structural_simplify(sys)
5353

5454
u0 = [D(x) => 2.0,
55-
x => 1.0,
56-
y => 0.0,
57-
z => 0.0]
55+
x => 1.0,
56+
y => 0.0,
57+
z => 0.0]
5858

59-
p ==> 28.0,
60-
ρ => 10.0,
61-
β => 8/3]
59+
p ==> 28.0,
60+
ρ => 10.0,
61+
β => 8 / 3]
6262

63-
tspan = (0.0,100.0)
64-
prob = ODEProblem(sys,u0,tspan,p,jac=true)
63+
tspan = (0.0, 100.0)
64+
prob = ODEProblem(sys, u0, tspan, p, jac = true)
6565
sol = solve(prob)
66-
using Plots; plot(sol,idxs=(x,y))
66+
using Plots
67+
plot(sol, idxs = (x, y))
6768
```
6869

6970
![Lorenz2](https://user-images.githubusercontent.com/1814174/79118645-744eb580-7d5c-11ea-9c37-13c4efd585ca.png)
@@ -81,42 +82,44 @@ using DifferentialEquations, ModelingToolkit
8182
@variables x(t) y(t) z(t)
8283
D = Differential(t)
8384

84-
eqs = [D(x) ~ σ*(y-x),
85-
D(y) ~ x*-z)-y,
86-
D(z) ~ x*y - β*z]
85+
eqs = [D(x) ~ σ * (y - x),
86+
D(y) ~ x *- z) - y,
87+
D(z) ~ x * y - β * z]
8788

8889
@named lorenz1 = ODESystem(eqs)
8990
@named lorenz2 = ODESystem(eqs)
9091

9192
@variables a(t)
9293
@parameters γ
93-
connections = [0 ~ lorenz1.x + lorenz2.y + a*γ]
94-
@named connected = ODESystem(connections,t,[a],[γ],systems=[lorenz1,lorenz2])
94+
connections = [0 ~ lorenz1.x + lorenz2.y + a * γ]
95+
@named connected = ODESystem(connections, t, [a], [γ], systems = [lorenz1, lorenz2])
96+
sys = structural_simplify(connected)
9597

9698
u0 = [lorenz1.x => 1.0,
97-
lorenz1.y => 0.0,
98-
lorenz1.z => 0.0,
99-
lorenz2.x => 0.0,
100-
lorenz2.y => 1.0,
101-
lorenz2.z => 0.0,
102-
a => 2.0]
103-
104-
p = [lorenz1.σ => 10.0,
105-
lorenz1.ρ => 28.0,
106-
lorenz1.β => 8/3,
107-
lorenz2.σ => 10.0,
108-
lorenz2.ρ => 28.0,
109-
lorenz2.β => 8/3,
110-
γ => 2.0]
111-
112-
tspan = (0.0,100.0)
113-
prob = ODEProblem(connected,u0,tspan,p)
99+
lorenz1.y => 0.0,
100+
lorenz1.z => 0.0,
101+
lorenz2.x => 0.0,
102+
lorenz2.y => 1.0,
103+
lorenz2.z => 0.0,
104+
a => 2.0]
105+
106+
p = [lorenz1.σ => 10.0,
107+
lorenz1.ρ => 28.0,
108+
lorenz1.β => 8 / 3,
109+
lorenz2.σ => 10.0,
110+
lorenz2.ρ => 28.0,
111+
lorenz2.β => 8 / 3,
112+
γ => 2.0]
113+
114+
tspan = (0.0, 100.0)
115+
prob = ODEProblem(sys, u0, tspan, p)
114116
sol = solve(prob)
115117

116-
using Plots; plot(sol,idxs=(a,lorenz1.x,lorenz2.z))
118+
using Plots
119+
plot(sol, idxs = (a, lorenz1.x, lorenz2.z))
117120
```
118121

119-
![](https://user-images.githubusercontent.com/1814174/110242538-87461780-7f24-11eb-983c-4b2c93cfc909.png)
122+
![](https://user-images.githubusercontent.com/17304743/187790221-528046c3-dbdb-4853-b977-799596c147f3.png)
120123

121124
# Citation
122125
If you use ModelingToolkit.jl in your research, please cite [this paper](https://arxiv.org/abs/2103.05244):

0 commit comments

Comments
 (0)