@@ -28,20 +28,14 @@ function lorenz(u0=[0.0, 10.0, 0.0]; σ = 10.0, ρ = 28.0, β = 8/3)
2828 return CoupledODEs (lorenz_rule, u0, [σ, ρ, β])
2929end
3030const lorenz63 = lorenz
31- function lorenz_rule (u, p, t)
32- @inbounds begin
33- σ = p[1 ]; ρ = p[2 ]; β = p[3 ]
34- du1 = σ* (u[2 ]- u[1 ])
35- du2 = u[1 ]* (ρ- u[3 ]) - u[2 ]
36- du3 = u[1 ]* u[2 ] - β* u[3 ]
37- return SVector {3} (du1, du2, du3)
38- end
31+ @inbounds function lorenz_rule (u, p, t)
32+ du1 = p[1 ]* (u[2 ]- u[1 ])
33+ du2 = u[1 ]* (ρ- u[3 ]) - u[2 ]
34+ du3 = u[1 ]* u[2 ] - p[3 ]* u[3 ]
35+ return SVector {3} (du1, du2, du3)
3936end
40- function lorenz_jacob (u, p, t)
41- @inbounds begin
42- σ, ρ, β = p
43- return SMatrix {3,3} (- σ, ρ - u[3 ], u[2 ], σ, - 1 , u[1 ], 0 , - u[1 ], - β)
44- end
37+ @inbounds function lorenz_jacob (u, p, t)
38+ return SMatrix {3,3} (- p[1 ], p[2 ] - u[3 ], u[2 ], p[1 ], - 1.0 , u[1 ], 0.0 , - u[1 ], - p[3 ])
4539end
4640
4741
@@ -84,20 +78,16 @@ function's documentation string.
8478function chua (u0 = [0.7 , 0.0 , 0.0 ]; a = 15.6 , b = 25.58 , m0 = - 8 / 7 , m1 = - 5 / 7 )
8579 return CoupledODEs (chua_rule, u0, [a, b, m0, m1], chua_jacob)
8680end
87- function chua_rule (u, p, t)
88- @inbounds begin
89- a, b, m0, m1 = p
90- du1 = a * (u[2 ] - u[1 ] - chua_element (u[1 ], m0, m1))
81+ @inbounds function chua_rule (u, p, t)
82+ du1 = p[1 ] * (u[2 ] - u[1 ] - chua_element (u[1 ], p[3 ], p[4 ]))
9183 du2 = u[1 ] - u[2 ] + u[3 ]
92- du3 = - b * u[2 ]
84+ du3 = - p[ 2 ] * u[2 ]
9385 return SVector {3} (du1, du2, du3)
94- end
9586end
9687function chua_jacob (u, p, t)
97- a, b, m0, m1 = p
98- return @SMatrix [- a* (1 + chua_element_derivative (u[1 ], m0, m1)) a 0 ;
99- 1 - 1 1 ;
100- 0 - b 0 ]
88+ return SMatrix {3,3} (- p[1 ]* (1 + chua_element_derivative (u[1 ], p[3 ], p[4 ])), p[1 ], 0.0 ,
89+ 1.0 , - 1.0 , 1.0 ,
90+ 0.0 , - p[2 ], 0.0 )
10191end
10292# Helper functions for Chua's circuit.
10393function chua_element (x, m0, m1)
@@ -132,23 +122,19 @@ function's documentation string.
132122
133123[^Rössler1976]: O. E. Rössler, Phys. Lett. **57A**, pp 397 (1976)
134124"""
135- function roessler (u0= [1 , - 2 , 0.1 ]; a = 0.2 , b = 0.2 , c = 5.7 )
125+ function roessler (u0= [1.0 , - 2.0 , 0.1 ]; a = 0.2 , b = 0.2 , c = 5.7 )
136126 return CoupledODEs (roessler_rule, u0, [a, b, c], roessler_jacob)
137127end
138- function roessler_rule (u, p, t)
139- @inbounds begin
140- a, b, c = p
128+ @inbounds function roessler_rule (u, p, t)
141129 du1 = - u[2 ]- u[3 ]
142- du2 = u[1 ] + a * u[2 ]
143- du3 = b + u[3 ]* (u[1 ] - c )
130+ du2 = u[1 ] + p[ 1 ] * u[2 ]
131+ du3 = p[ 2 ] + u[3 ]* (u[1 ] - p[ 3 ] )
144132 return SVector {3} (du1, du2, du3)
145- end
146133end
147134function roessler_jacob (u, p, t)
148- a, b, c = p
149- return @SMatrix [0.0 (- 1.0 ) (- 1.0 );
150- 1.0 a 0.0 ;
151- u[3 ] 0.0 (u[1 ]- c)]
135+ return SMatrix {3,3} (0.0 , - 1.0 , - 1.0 ,
136+ 1.0 , p[1 ], 0.0 ,
137+ u[3 ], 0.0 , u[1 ]- p[3 ])
152138end
153139
154140"""
@@ -179,7 +165,7 @@ Jacobian is created automatically (thus methods that use the Jacobian will be sl
179165The parameter container has the parameters in the same order as stated in this
180166function's documentation string.
181167"""
182- function double_pendulum (u0= [π/ 2 , 0 , 0 , 0.5 ];
168+ function double_pendulum (u0= [π/ 2 , 0.0 , 0. 0 , 0.5 ];
183169 G= 10.0 , L1 = 1.0 , L2 = 1.0 , M1 = 1.0 , M2 = 1.0 )
184170 return CoupledODEs (doublependulum_rule, u0, [G, L1, L2, M1, M2])
185171end
@@ -224,13 +210,13 @@ The function `Systems.henonheiles_ics(E, n)` generates a grid of
224210
225211[^HénonHeiles1964]: Hénon, M. & Heiles, C., The Astronomical Journal **69**, pp 73–79 (1964)
226212"""
227- function henonheiles (u0= [0 , - 0.25 , 0.42081 , 0 ])
213+ function henonheiles (u0= [0.0 , - 0.25 , 0.42081 , 0. 0 ])
228214 return CoupledODEs (henonheiles_rule, u0, nothing )
229215end
230216@inbounds function henonheiles_rule (u, p, t)
231217 du1 = u[3 ]
232218 du2 = u[4 ]
233- du3 = - u[1 ] - 2 u [1 ]* u[2 ]
219+ du3 = - u[1 ] - 2.0 * u [1 ]* u[2 ]
234220 du4 = - u[2 ] - (u[1 ]^ 2 - u[2 ]^ 2 )
235221 return SVector (du1, du2, du3, du4)
236222end
@@ -292,22 +278,15 @@ The default initial condition is chaotic.
292278 Micluta-Campeanu S., Raportaru M.C., Nicolin A.I., Baran V., Rom. Rep. Phys.
293279 **70**, pp 105 (2018)
294280"""
295- function qbh (u0= [0. , - 2.5830294658973876 , 1.3873470962626937 , - 4.743416490252585 ]; A= 1. , B= 0.55 , D= 0.4 )
281+ function qbh (u0= [0.0 , - 2.5830294658973876 , 1.3873470962626937 , - 4.743416490252585 ]; A= 1.0 , B= 0.55 , D= 0.4 )
296282 return CoupledODEs (qrule, u0, [A, B, D])
297283end
298- function qrule (z, p, t)
299- @inbounds begin
300- A, B, D = p
301- p₀, p₂ = z[1 ], z[2 ]
302- q₀, q₂ = z[3 ], z[4 ]
303-
304- return SVector {4} (
305- - A * q₀ - 3 * B / √ 2 * (q₂^ 2 - q₀^ 2 ) - D * q₀ * (q₀^ 2 + q₂^ 2 ),
306- - q₂ * (A + 3 * √ 2 * B * q₀ + D * (q₀^ 2 + q₂^ 2 )),
307- A * p₀,
308- A * p₂
309- )
310- end
284+ @inbounds function qrule (u, p, t)
285+ u1 = p[1 ] * u[1 ]
286+ u2 = p[1 ] * u[2 ]
287+ u3 = - p[1 ] * u[3 ] - 3.0 * p[2 ] / √ 2.0 * (u[4 ]^ 2 - u[3 ]^ 2 ) - p[3 ] * u[3 ] * (u[3 ]^ 2 + u[4 ]^ 2 )
288+ u4= - u[4 ] * (p[1 ] + 3.0 * √ 2.0 * p[2 ] * u[3 ] + p[3 ] * (u[3 ]^ 2 + u[4 ]^ 2 ))
289+ return SVector {4} (u1, u2, u3, u4)
311290end
312291
313292"""
@@ -326,15 +305,14 @@ function lorenz96(N::Int, u0 = range(0; length = N, step = 0.1); F=0.01)
326305 return CoupledODEs (lor96, u0, [F])
327306end
328307struct Lorenz96{N} end # Structure for size type
329- function (obj:: Lorenz96{N} )(dx, x, p, t) where {N}
330- F = p[1 ]
308+ @inbounds function (obj:: Lorenz96{N} )(dx, x, p, t) where {N}
331309 # 3 edge cases
332- @inbounds dx[1 ] = (x[2 ] - x[N - 1 ]) * x[N] - x[1 ] + F
333- @inbounds dx[2 ] = (x[3 ] - x[N]) * x[1 ] - x[2 ] + F
334- @inbounds dx[N] = (x[1 ] - x[N - 2 ]) * x[N - 1 ] - x[N] + F
310+ dx[1 ] = (x[2 ] - x[N - 1 ]) * x[N] - x[1 ] + p[ 1 ]
311+ dx[2 ] = (x[3 ] - x[N]) * x[1 ] - x[2 ] + p[ 1 ]
312+ dx[N] = (x[1 ] - x[N - 2 ]) * x[N - 1 ] - x[N] + p[ 1 ]
335313 # then the general case
336314 for n in 3 : (N - 1 )
337- @inbounds dx[n] = (x[n + 1 ] - x[n - 2 ]) * x[n - 1 ] - x[n] + F
315+ dx[n] = (x[n + 1 ] - x[n - 2 ]) * x[n - 1 ] - x[n] + p[ 1 ]
338316 end
339317 return nothing
340318end
0 commit comments