Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1
using PlutoUI, Plots
888 ms
plotly()
150 ms

the logistic map

read Sethna sec 4.3

results

xn+1=rxn(1xn)

  • r in 1:3 stable

  • 3 < r < 3.45 oscillation between 2 values

  • r > 3.45 CRAZY

md"
# the logistic map

## read Sethna sec 4.3

## results

```math
\begin{aligned}
x_{n+1} = r \, x_n \, (1 - x_n)
\end{aligned}
```

* r in 1:3 stable
* 3 < r < 3.45 oscillation between 2 values
* r > 3.45 CRAZY

"
4.5 ms
logistic_map (generic function with 1 method)
function logistic_map(x; r = 0.5)
# iterate once
return r * x * (1 - x)
end
830 μs
slider_N1
10
slider_N1 = @bind N1 Slider(0:5:80, show_value = true, default = 10)
59.3 ms
slider_rr
2.5
slider_rr = @bind rr Slider(0.0:0.1:4.0, show_value = true, default = 2.5)
49.7 ms
051015200.000.250.500.751.00
y1y21-1/rno. of iter.the logistic map @ r=2.8
let

# different starting points
x1 = 0.01
x2 = 0.9

x1arr = [x1]
x2arr = [x2]

for i1 = 1:N1

x1 = logistic_map(x1; r = rr)
x2 = logistic_map(x2; r = rr)

push!(x1arr, x1)
push!(x2arr, x2)
end

Plots.scatter(0:N1, x1arr, ylim = (0, 1.1))
Plots.scatter!(0:N1, x2arr, ylim = (0, 1.1), title="the logistic map @ r=$rr", xlabel="no. of iter.")

# analytic limit
Plots.plot!(0:N1, x -> 1 - 1 / rr, label = "1-1/r")



end
1.6 ms
0.000.250.500.751.000.000.250.500.751.00
xf(x)f(f(x))f(f(f(x)))f(f(f(f(x))))
let

# visual aid to understand end points
# r = 3.4 has 2 end points

# solution is at x = f(x) = f(f(x)) = ...
r = 3.4
f(x) = r * x * (1 - x)

Plots.plot(range(0.0, 1.0, length = 20), x -> x, label = "x")
Plots.plot!(range(0.0, 1.0, length = 20), x -> f(x), label = "f(x)")
Plots.plot!(range(0.0, 1.0, length = 20), x -> f(f(x)), label = "f(f(x))")
Plots.plot!(range(0.0, 1.0, length = 20), x -> f(f(f(x))), label = "f(f(f(x)))")
Plots.plot!(range(0.0, 1.0, length = 20), x -> f(f(f(f(x)))), label = "f(f(f(f(x))))")

end
118 ms

invariant density: a histogram of a trajectory at a given r

md"

# invariant density: a histogram of a trajectory at a given r

"
142 μs
0.000.250.500.751.0002468
numericalanalytic (r=4)invariant density @ r = 3.61
let

# invariant density
# just plot the number of occurances in a histogram

rval = 3.61

x_arr = []

x = 0.28
for i1 = 1:85000

x = logistic_map(x; r = rval)

push!(x_arr, x)
end

# for r = 4
f(x) = 1 / sqrt(x * (1 - x)) / pi

histogram(x_arr, normalize = true, bins = 150, label="numerical")
plot!(0:0.01:1, f,
label="analytic (r=4)",
title="invariant density @ r = $rval"
)


end
148 ms
let
rarr = range(0.5, 4.1, length = 140)

function track(r1)
xarr = []
x = 0.8
for i1 = 1:120
x = logistic_map(x; r = r1)
push!(xarr, x)
end
return xarr
end

function plot_one(i1)
return scatter!(
r -> track(r)[end-i1],
markersize = 0.8,
color="black",
ylim = (0, 1),
label = "",
)
end

fig = plot(rarr, r->1-1/r, label="analytic (small r)")

for i1 = 1:20
fig = plot_one(i1)
end

119 ms

other map

xn+1=rsin(πxn)

or

xn+1=xner(1xn)

have similar feature.

md"
# other map

```math
\begin{aligned}
x_{n+1} = r \, sin(\pi \, x_n)
\end{aligned}
```

or

```math
\begin{aligned}
x_{n+1} = x_n \, e^{\, r \, (1-x_n)}
\end{aligned}
```


have similar feature.

"
194 μs
let

# there nothing special about the function r*x*(1-x)
# a sine function map will work too

function sin_map(x; r = 0.5)
# iterate once
return r * sin(x * pi)
end

rarr = range(0.0, 1.2, length = 120)

function track(r1)
xarr = []
x = 0.8
for i1 = 1:80
x = sin_map(x; r = r1)
push!(xarr, x)
end
return xarr
end

function plot_one(i1)
return scatter!(
r -> track(r)[end-i1],
markersize = 0.8,
ylim = (0, 1.2),
138 ms
let

# yet another map

function exp_map(x; r = 0.5)
# iterate once
return x * exp(r * (1 - x))
end

rarr = range(1.4, 4.0, length = 180)

function track(r1)
xarr = []
x = 0.4
for i1 = 1:80
x = exp_map(x; r = r1)
push!(xarr, x)
end
return xarr
end

function plot_one(i1)
return scatter!(
r -> track(r)[end-i1],
markersize = 0.8,
ylim = (0, 4.0),
label = "",
)
end
114 ms

further reading

  • runs this with more points offline

  • https://www.google.com/search?q=logistic+map

  • J.F. Boudreau and E.S. Swanson, Applied Computational Physics (ch.13)

  • simple math models

  • what about matrix?

md"
# further reading

* runs this with more points offline
* https://www.google.com/search?q=logistic+map
* J.F. Boudreau and E.S. Swanson, Applied Computational Physics (ch.13)

* [simple math models](https://www.nature.com/articles/261459a0)
* what about matrix?

"
387 μs
using LinearAlgebra
201 μs
let

# not sure what is going on
# just for fun

rarr = range(0.01, 2.8, length = 50)

function logi(x; r = 0.5)
# iterate once
return r * sin(pi * x)
end

function track(r1)
xarr = []
x = reshape(rand(4), (2, 2))
for i1 = 1:120
x = logi(x; r = r1)
dd = abs(det(x))
push!(xarr, dd)
end
return xarr
end

function plot_one(i1)
return scatter!(
r -> track(r)[end-i1],
markersize = 0.8,
ylim = (0, 3.5),
2.2 s