Discrete Maps using DifferentialEquations.jl
Hénon Map
The Hénon map is a classic example of a simple discrete dynamical system with an attractor which is neither a periodic point or a periodic orbit (or any other smooth invariant object) but a strange attractor. The equations are \[ x_{n+1}= 1-ax_n^2+y_n, \quad y_{n+1}=bx_n \] where \(a\) and \(b\) are parameters.
using DifferentialEquations,Plots
function henon_map!(u1,u,p=Float64[1.4,0.3],t=0)
= u
x,y= p
a,b1]=1-a*x^2+y
u1[2]= b*x
u1[nothing
end
= (0.0,10_000_000)
tspan =u0=Float64[1,1]
u=ODEFunction(henon_map!,syms = [:x, :y])
f= DiscreteProblem(f,
prob Float64[1.4,0.3])
u0,tspan,@time sol = solve(prob)
scatter(sol[100:10_000:end],
=(1,2),
idxs=.01,
markersize=0.1,
alpha=false)
legend
savefig("./henon.png")
When plotting a large number of points, like this case, it is not very efficient because poitns are not going to plot many points in the same pixels. To obtain the visual effect of clustering of different passages at the same point we use alpha=0.1
for transparency.
To make the plot faster and more informative, we can simply plot a histogram2d:
histogram2d(sol[100:end],
=(1,2),
idxs=1000,
bins=false)
legend
savefig("henon_as_histogram.png")
and now the colors represent the relative frequency that regions in the \((x,y)\) are visited by the orbits.
Finally, we export the dataset for further use
using DataFrames,CSV
= DataFrame(sol)
df write("./henon.csv",df) CSV.
so that we can also plot it with R
See also https://www.r-bloggers.com/2019/10/strange-attractors-an-r-experiment-about-maths-recursivity-and-creative-coding/
Extension: Clifford Attractors
Taken from https://fronkonstin.com/2017/11/07/drawing-10-million-points-with-ggplot-clifford-attractors/
Clifford attractors are a visually appealing example of strange attractors given by the iteration of a 2D system.
\[ x_{n+1}\, = \sin(a\, y_{n})\, +\, c\, \cos(a\, x_{n}) \]
\[ y_{n+1}\, = \sin(b\, x_{n})\, +\, d\, \cos(b\, y_{n}) \]
where \(a,b,c\) and \(d\) are different parameters. A choice of parameters is
a=-1.24458046630025 b=-1.25191834103316 c=-1.81590817030519 d=-1.90866735205054
Let us produce the plot:
using DifferentialEquations
function clifford_map!(u1,u,p,t=0)
= u
x,y= p
a,b,c,d1]=sin(a*y)+c*cos(a*x)
u1[2]= sin(b*x)+d*cos(b*y)
u1[nothing
end
= (0.0,100_000)
tspan =u0=Float64[0,0]
u=Float64[-1.24458046630025,
p0-1.25191834103316,
-1.81590817030519,
-1.90866735205054]
=ODEFunction(clifford_map!,syms = [:x, :y])
f= DiscreteProblem(f,
prob
u0,tspan,p0)@time sol = solve(prob)
scatter(sol[100:end],
=(1,2),
idxs=.01,
markersize=0.1,
alpha=false,
legend= (1200, 1000))
size
savefig("./clifford.png")
histogram2d(sol[100:end],
=(1,2),
idxs=2000,
bins=false,
legend= (1200, 1000))
size
savefig("./clifford_as_histogram.png")
We finally save it as a csv file for later use
using DataFrames,CSV
= DataFrame(sol)
df write("./clifford.csv",df) CSV.