https://youtu.be/LYyTLMyivUk?si=zy8KpL3jwl85ybfQ
λ§λΈλΈλ‘ μ§ν©μ μ€μ λ‘ κ·Έλ¦΄ λμλ μ νμμ λ°λΌ znμ κ³μ°νλ©΄μ μμ΄μ΄ λ°μ°νλμ§ κ·Έλ μ§ μμμ§λ₯Ό λμμ μΌλ‘ κ²μ¬νκ² λλ€. znμ μ λκ°μ΄ 2λ³΄λ€ ν¬λ€λ©΄(μ¦, xn2+yn2>22μ΄λΌλ©΄) znμ λ°μ°νλ€κ³ λ§ν μ μμΌλ©°, μ΄ λμ cλ λ§λΈλΈλ‘ μ§ν©μ μν΄ μμ§ μλλ€. μ΄ λμ 2λΌλ κ°μ λ°μ°νλ μμ΄μ κ³μ°μ 미리 λ§μ μ£Όλ μν μ νλ©°, κ²½κ³κ°μ΄λΌκ³ λΆλ₯Έλ€. λ°λ©΄ λ§λΈλΈλ‘ μ§ν© μμ μν΄ μλ μ μ κ²½μ° znμ λ°μ°νμ§ μμΌλ―λ‘ λ¬΄νν κ³μ°ν΄λ λλμ§ μμ κ²μ΄λ€. μ΄λ° κ²½μ°μλ μ μ ν nκ° μ΄νμ κ³μ°μ λ©μΆμ΄μΌλ§ νλ€. 무νν κ³μ°νμ§ μλ ν μ°λ¦¬λ μ΄λ‘ μ μΈ λ§λΈλΈλ‘ μ§ν©μ΄ μλ μ΄μ κ·Όμ¬ν μ§ν©λ§ μ»μ μλ°μ μλ€.
# μΉ΄μ€μ€μ²λΌ 보μ΄λ λμμ μ§ν©μ΄ μΌμ ν μ£ΌκΈ°λ₯Ό κ°λλ€. μ΄λ¬ν μμ μ§ν©μ λ§λΈλΈλ‘ μ§ν©μ΄λΌ νλ€.
Formula : Zn+1 = Zn^2 + C
# C = 1
Zn+1 = Zn^2 + C
1 = 0 + 1
2 = 1^2 + 1
5 = 2^2 + 1
26 = 5^2 + 1
.
.
.
.
## λ°μ°
# C = -1
Zn+1 = Zn^2 + C
-1 = 0 -1
0 = -1^2 -1
-1 = 0^2 -1
0 = -1^2 -1
.
.
## 0, -1 λ°λ³΅
Python ꡬν
import numpy as np
import matplotlib.pyplot as plt
def mandelbrot(c, max_iter):
z = 0
n = 0
while abs(z) <= 2 and n < max_iter:
z = z**2 + c
n += 1
if n == max_iter:
return max_iter
return n + 1 - np.log(np.log2(abs(z)))
def mandelbrot_set(width, height, x_min, x_max, y_min, y_max, max_iter):
x, y = np.meshgrid(np.linspace(x_min, x_max, width), np.linspace(y_min, y_max, height))
c = x + 1j * y
mandelbrot_image = np.vectorize(mandelbrot)(c, max_iter)
return mandelbrot_image
def plot_mandelbrot(width, height, x_min, x_max, y_min, y_max, max_iter):
mandelbrot_image = mandelbrot_set(width, height, x_min, x_max, y_min, y_max, max_iter)
plt.imshow(mandelbrot_image, extent=(x_min, x_max, y_min, y_max), cmap='hot', interpolation='bilinear')
plt.colorbar()
plt.title('Mandelbrot Set')
plt.show()
# 맀κ°λ³μ μ€μ
width, height = 800, 800
x_min, x_max = -2, 1
y_min, y_max = -1.5, 1.5
max_iter = 100
# 맨λ€λΈλ‘ μ§ν© 그리기
plot_mandelbrot(width, height, x_min, x_max, y_min, y_max, max_iter)
'π Python' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Pytest] ERROR: file or directory not found (0) | 2023.12.13 |
---|---|
[pipx] python μ μ ν¨ν€μ§κ΄λ¦¬ pipx (0) | 2023.11.29 |
[Version] 3.12 rc (Release Candidates) (2) - kwargs, override (0) | 2023.10.26 |
[Version] 3.12 rc (Release Candidates) (1) - f-string (0) | 2023.10.18 |
[JupyterNote Book] Jupytext Notebook -> Markdown (0) | 2023.09.30 |