You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# `henon` is a `DynamicalSystem`, one of the two core structures of the library.
106
-
# They can evolved interactively, and queried, using the interface defined by [`DynamicalSystem`](@ref). The simplest thing you can do with a `DynamicalSystem` is to get its trajectory:
106
+
# They can evolved interactively, and queried, using the interface defined by [`DynamicalSystem`](@ref).
107
+
# The simplest thing you can do with a `DynamicalSystem` is to get its trajectory:
107
108
108
109
total_time =10_000
109
110
X, t =trajectory(henon, total_time)
110
111
X
111
112
112
-
# `X` is a `StateSpaceSet`, the second of the core structures of the library. We'll see below how, and where, to use a `StateSpaceset`, but for now let's just do a scatter plot
113
+
# `X` is a `StateSpaceSet`, the second of the core structures of the library.
114
+
# We'll see below how, and where, to use a `StateSpaceset`, but for now let's just do a scatter plot
113
115
114
116
using CairoMakie
115
-
scatter(X[:, 1], X[:, 2])
117
+
scatter(X)
116
118
117
119
# ### Example: Lorenz96
118
120
@@ -167,15 +169,15 @@ fig
167
169
# Continuous time dynamical systems are evolved through DifferentialEquations.jl.
168
170
# In this sense, the above `trajectory` function is a simplified version of `DifferentialEquations.solve`.
169
171
# If you only care about evolving a dynamical system forwards in time, you are probably better off using
170
-
# DifferentialEquations.jl directly. DynamicalSystems.jl can be used to do many other things that either occur during
172
+
# DifferentialEquations.jl directly. **DynamicalSystems.jl** can be used to do many other things that either occur during
171
173
# the time evolution or after it, see the section below on [using dynamical systems](@ref using).
172
174
173
175
# When initializing a `CoupledODEs` you can tune the solver properties to your heart's
174
176
# content using any of the [ODE solvers](https://diffeq.sciml.ai/latest/solvers/ode_solve/)
175
177
# and any of the [common solver options](https://diffeq.sciml.ai/latest/basics/common_solver_opts/).
176
178
# For example:
177
179
178
-
using OrdinaryDiffEq # accessing the ODE solvers
180
+
using OrdinaryDiffEq: Vern9# accessing the ODE solvers
# The solver `Tsit5` (the default solver) is most performant when medium-high error
193
-
# tolerances are requested. When we require very small errors, choosing a different solver
194
+
# The solver `Tsit5` (the default solver) is most performant when medium-low error
195
+
# tolerances are requested. When we require very small error tolerances, choosing a different solver
194
196
# can be more accurate. This can be especially impactful for chaotic dynamical systems.
195
197
# Let's first expliclty ask for a given accuracy when solving the ODE by passing the
196
198
# keywords `abstol, reltol` (for absolute and relative tolerance respectively),
197
199
# and compare performance to a naive solver one would use:
198
200
199
201
using BenchmarkTools:@btime
200
-
using OrdinaryDiffEq: BS3 #equivalent of odeint23
202
+
using OrdinaryDiffEq: BS3 #3rd order solver
201
203
202
204
for alg in (BS3(), Vern9())
203
205
diffeq = (; alg, abstol =1e-12, reltol =1e-12)
@@ -230,6 +232,8 @@ end
230
232
231
233
# Let's compare
232
234
235
+
using OrdinaryDiffEq: Tsit5, Rodas5P
236
+
233
237
functionvanderpol_rule(u, μ, t)
234
238
x, y = u
235
239
dx = y
@@ -252,14 +256,28 @@ end
252
256
253
257
# ## [Using dynamical systems](@id using)
254
258
255
-
# You may use the [`DynamicalSystem`](@ref) interface to develop algorithms that utilize dynamical systems with a known evolution rule. The two main packages of the library that do this are [`ChaosTools`](@ref) and [`Attractors`](@ref). For example, you may want to compute the Lyapunov spectrum of the Lorenz96 system from above. This is as easy as calling the `lyapunovspectrum` function with `lorenz96`
259
+
# You may use the [`DynamicalSystem`](@ref) interface to develop algorithms that utilize dynamical systems with a known evolution rule.
260
+
# The two main packages of the library that do this are [`ChaosTools`](@ref) and [`Attractors`](@ref).
261
+
# For example, you may want to compute the Lyapunov spectrum of the Lorenz96 system from above.
262
+
# This is as easy as calling the `lyapunovspectrum` function with `lorenz96`
256
263
257
264
steps =10_000
258
265
lyapunovspectrum(lorenz96, steps)
259
266
260
-
# As expected, there is at least one positive Lyapunov exponent, because the system is chaotic, and at least one zero Lyapunov exponent, because the system is continuous time.
267
+
# As expected, there is at least one positive Lyapunov exponent, because the system is chaotic,
268
+
# and at least one zero Lyapunov exponent, because the system is continuous time.
269
+
270
+
# A fantastic feature of **DynamicalSystems.jl** is that all library functions work for any
271
+
# applicable dynamical system. The exact same `lyapunovspectrum` function would also work
272
+
# for the Henon map.
261
273
262
-
# Alternatively, you may want to estimate the basins of attraction of a multistable dynamical system. The Henon map is "multistable" in the sense that some initial conditions diverge to infinity, and some others converge to a chaotic attractor. Computing these basins of attraction is simple with [`Attractors`](@ref), and would work as follows:
274
+
lyapunovspectrum(henon, steps)
275
+
276
+
# Something else that uses a dynamical system is estimating the basins of attraction
277
+
# of a multistable dynamical system.
278
+
# The Henon map is "multistable" in the sense that some initial conditions diverge to
279
+
# infinity, and some others converge to a chaotic attractor.
280
+
# Computing these basins of attraction is simple with [`Attractors`](@ref), and would work as follows:
263
281
264
282
## define a state space grid to compute the basins on:
265
283
xg = yg =range(-2, 2; length =201)
@@ -315,7 +333,12 @@ step!(henon, 2)
315
333
316
334
X
317
335
318
-
# It is printed like a matrix where each column is the timeseries of each dynamic variable. In reality, it is a vector of statically sized vectors (for performance reasons). When indexed with 1 index, it behaves like a vector of vectors
336
+
# This is the main data structure used in **DynamicalSystems.jl** to handle numerical data.
337
+
# It is printed like a matrix where each column is the timeseries of each dynamic variable.
338
+
# In reality, it is a vector equally-sized vectors representing state space points.
# Because `StateSpaceSet` really is a vector of vectors, it can be given
370
+
# to any Julia function that accepts such an input. For example,
371
+
# the Makie plotting ecosystem knows how to plot vectors of vectors.
372
+
# That's why this works:
373
+
374
+
scatter(X)
375
+
376
+
# even though Makie has no knowledge of the specifics of `StateSpaceSet`.
377
+
346
378
# ## Using state space sets
347
379
348
380
# Several packages of the library deal with `StateSpaceSets`.
@@ -420,7 +452,7 @@ fig
420
452
421
453
# ## Integration with ModelingToolkit.jl
422
454
423
-
# DynamicalSystems.jl understands when a model has been generated via [ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/). The symbolic variables used in ModelingToolkit.jl can be used to access the state or parameters of the dynamical system.
455
+
#**DynamicalSystems.jl** understands when a model has been generated via [ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/). The symbolic variables used in ModelingToolkit.jl can be used to access the state or parameters of the dynamical system.
424
456
425
457
# To access this functionality, the `DynamicalSystem` must be created from a `DEProblem` of the SciML ecosystem, and the `DEProblem` itself must be created from a ModelingToolkit.jl model.
# To learn more, you need to visit the documentation pages of the modules that compose DynamicalSystems.jl. See the [contents](@ref contents) page for more!
549
+
# To learn more, you need to visit the documentation pages of the modules that compose **DynamicalSystems.jl**. See the [contents](@ref contents) page for more!
0 commit comments