Since August 22, 2016, I have been on a business trip to Malaysia for two months. Since I live in a hotel and have free time on holidays, I decided to make a hobby program for the first time in a while.
Regarding fractals, I have drawn Mandelbrot, Buddhabrot, Julia set, etc., but all of them calculated the color of the coordinates in Fortran and output it in GMT, but this time I decided to try it all in Python did.
As a drawing function, the heat map drawing function (pcolor) of Python-matplotlib is used. It is necessary to prepare the x-coordinate, y-coordinate, and z-value (values that indicate colors on the drawing) in a two-dimensional array, but the coding for drawing can be very simple and convenient for such drawing.
The following program is a Python version of the BASIC program described in the reference site (1). I changed it a little for my hobby.
The variables to change are as follows
ab td> | Create the basic character string (one-dimensional array in the program) you want to draw as a = 0, b = 1 td> tr> |
nm td> | Number of iterations of one-dimensional array * ab * td> tr> |
a0, a1 td> | x-axis range td> tr> |
b0, b1 td> | y-axis range td> tr> |
irx, iry td> | x-axis range and y-axis range divisions td> tr> |
py_lyapunov0.py
import numpy as np
import matplotlib.pyplot as plt
ab=np.array([0,1])
nab=len(ab)
nm=10
a0=2
a1=4
b0=2
b1=4
irx=800
iry=600
x = np.linspace(a0,a1,irx+1)
y = np.linspace(b0,b1,iry+1)
X, Y = np.meshgrid(x, y)
z=np.empty((iry+1,irx+1))
for i in range(0,irx+1):
a=a0+(a1-a0)/(irx)*i
for j in range(0,iry+1):
b=b0+(b1-b0)/(iry)*j
s=0
xx=0.5
for n in range(0,nm):
for m in range(0,nab):
if ab[m]==0:
rr=a
else:
rr=b
xx=rr*xx*(1-xx)
v=np.abs(rr*(1-2*xx))
if 0<v: s=s+np.log(v)
s=s/(nm*nab)
if 2<s:
z[j,i]=2
elif s<-5:
z[j,i]=-5
else:
z[j,i]=s
print(np.max(z))
print(np.min(z))
z=-1.0*z
plt.xlim(a0,a1)
plt.ylim(b0,b1)
plt.pcolor(X, Y, z, cmap=plt.cm.spectral)
plt.colorbar()
plt.show()
An example of drawing with the variables described in the above program is shown below.
(1) Lyapunov Fractal drawing program example http://www.rowan.edu/colleges/csm/departments/math/facultystaff/osler/15.%20A%20quick%20look%20at%20Lyapunov%20space.pdf
(2) Heat map example http://yoshihikomuto.hatenablog.jp/entry/2015/04/10/105615
(3) Heat map basics http://d.hatena.ne.jp/y_n_c/20091122/1258904025
(4) Lyapunov Fractal (Wikipedia) [https://ja.wikipedia.org/wiki/%E3%83%AA%E3%82%A2%E3%83%97%E3%83%8E%E3%83%95%E3%83%BB%E3%83%95%E3%83%A9%E3%82%AF%E3%82%BF%E3%83%AB] (https://ja.wikipedia.org/wiki/%E3%83%AA%E3%82%A2%E3%83%97%E3%83%8E%E3%83%95%E3%83%BB%E3%83%95%E3%83%A9%E3%82%AF%E3%82%BF%E3%83%AB)
that's all
Recommended Posts