-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbifurcation_binned.jl
66 lines (52 loc) · 1.74 KB
/
bifurcation_binned.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Generate a bifurcation diagram of the logistic equation
Author: Subhodeep Sarkar
Contact: [email protected]
Date: 01-08-2023
Note: Modify a_N, itMAX, nBINS to control the quality
of the bifurcation diagram
"""
# import packages
using Plots
using LaTeXStrings
using BenchmarkTools
# define functions
function logistic(a_val, x_val)
return a_val * x_val * (1 - x_val)
end
function compute_data(data, as, x0, ithide, itmax, nbins)
for a_idx in eachindex(as)
x = x0
for i = 1:ithide
x = logistic(as[a_idx], x)
end
for i = 1:itmax
x = logistic(as[a_idx], x)
index = ceil(Int, nbins * x)
data[index, a_idx] += 1
end
end
return data
end
@btime begin
# parameters and initialization
amin, amax, a_N = 2.8, 4.0, 10000 # limits of the x axis and number of points
as_vals = range(amin, amax, a_N) # range of a (x axis)
itMAX = 2500000 # number of iterations for each a
itHIDE = 100000 # number of hidden iterations before plotting
xtiny = 1e-10 # initial value for x
nBINS = 3000 # resolution along the y axis
data_arr = zeros(nBINS, a_N) # array to store the computed data
# main execution
data_arr = compute_data(data_arr, as_vals, xtiny, itHIDE, itMAX, nBINS)
data_arr ./= maximum(data_arr, dims=1) # normalization
# plotting
xmin, xmax = 0, 1 # range of x axis
xs = range(xmin, xmax, length=nBINS)
p = heatmap(as_vals, xs, log10.(data_arr), c=cgrad(:darktest, rev=false),
colorbar=false, grid=false, framestyle=:box)
xlabel!("\$\\alpha\$") # instead of the L marco
ylabel!(L"x_{n}")
title!(L"x_{n}=\alpha x_{n-1}(1-x_{n-1})")
savefig(p, "plots/bifurcation_binned.pdf")
end