This is a Python script which creates a Mandelbrot set using a Python library called Matplotlib.I have
Question:
This is a Python script which creates a Mandelbrot set using a Python library called Matplotlib.I have compiled the code using Thonny IDE.
import numpy as np
import matplotlib.pyplot as plt
def mandelbrot(c, max_iter):
z = c
for i in range(max_iter):
if abs(z) > 2.0:
return i
z = z**2 + c
return max_iter
def create_mandelbrot(width, height, x_min, x_max, y_min, y_max, max_iter):
image = np.zeros((height, width))
for x in range(width):
for y in range(height):
zx = np.interp(x, [0, width], [x_min, x_max])
zy = np.interp(y, [0, height], [y_min, y_max])
c = complex(zx, zy)
image[y, x] = mandelbrot(c, max_iter)
return image
# Set the parameters
width = 800
height = 800
x_min, x_max = -2.5, 1.5
y_min, y_max = -2.0, 2.0
max_iter = 100
# Create the Mandelbrot set image
image = create_mandelbrot(width, height, x_min, x_max, y_min, y_max, max_iter)
# Plot the image
plt.imshow(image.T, cmap='hot', extent=(x_min, x_max, y_min, y_max))
plt.title('Mandelbrot Set')
plt.xlabel('Re(c)')
plt.ylabel('Im(c)')
plt.colorbar(label='Iterations')
plt.show()
Horngrens Financial and Managerial Accounting
ISBN: 978-0133866292
5th edition
Authors: Tracie L. Nobles, Brenda L. Mattison, Ella Mae Matsumura