LoginSignup
8
7

More than 5 years have passed since last update.

[Python]マンデルブロ集合の描画

Last updated at Posted at 2018-12-11

はじめに

Pythonでマンデルブロ集合を描いてみました.

マンデルブロ集合とは

次の漸化式

\left\{
\begin{array}{ll}
z_{n+1}=z^2_{n}+c\\
z_{0}=0
\end{array}
\right.

で定義される複素数列$z_n$が$n\rightarrow\infty$で無限大に発散しないときの複素数$c$全体が作る集合のことをマンデルブロ集合と言います.

Mandelbrot.py

Mandelbrot.py
import numpy
from numba import autojit
import matplotlib.pyplot as plt

@autojit
def mandelbrot(Re, Im, max_iter):
    c = complex(Re, Im)
    z = 0.0j

    for i in range(max_iter):
        z = z*z + c
        if(z.real*z.real + z.imag*z.imag) >= 4:
            return i
    return max_iter

columns = 3000
rows = 3000

result = numpy.zeros([rows, columns])
for row_index, Re in enumerate(numpy.linspace(-2, 1, num=rows)):
    for column_index, Im in enumerate(numpy.linspace(-1, 1, num=columns)):
        result[row_index, column_index] = mandelbrot(Re, Im , 100)

plt.figure(dpi=120)
plt.imshow(result.T, cmap='bone', interpolation='bilinear', extent=[-2, 1, -1, 1])
plt.xticks(color='None')
plt.yticks(color='None')
plt.tick_params(length=0)
plt.show()

実行結果

Mandelbrot.png

おわりに

とても面白い図形です.ぜひ描いてみてください!

8
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7