The Mandelbrot set¶
The creation¶
The Mandelbrot set \(\mathcal{M}\) is defined as :
Given the fact that it is a set of points, we can compute it using a class Python object. Thus, determine which arguments to pass
in order to instantiate one set, and what methods to compute. What a user (you hopefully) might want to ask oneself is:
where should I center the picture of the Mandelbrot set?
do I want the whole set or just a special part? If the latest, what square exactly would I want to look at?
do I need of lot of iterations of the sequence: meaning more time to make, or can I be satisfied with a reasonable number of iterations?
Note
For only aesthetics purposes, we chose not to let the user display a rectangular part of the Mandelbrot set but only a square one.
So, the windows that will be displayed will be a square centered at the point \(a+bi\). The user will input this point separating
the real part and the imaginary part in the two arguments x and y. The size of the square is determined by the facteur
argument representing the half-length of the side of the square one’d like to display.
A summary to keep in mind¶
| Methods | Output | ||
|---|---|---|---|
| numpy array | saved video | matplotlib plot | |
| anim_puiss_mandel | X | ||
| anim_pics_mandel | X | ||
| animate_mandel_plt | X | ||
| disp_mandel | X | ||
| mandel_loop | X | ||
| mandel_transform | X | ||
| mandelbrot |
X | ||
The class methods¶
-
class
Mandelbrot_disp(x, y, facteur, t_max=100, precision=400)¶ Creates the mandlebrot graph and zooms in on this graph.
Moreover, there are functions who display the Mandlebrot set in 2D and 3D with animated video.
- Parameters
x (float) – coordinate of the image’s center
y (float) – coordinate on the Imaginary axis
facteur (float) – the remoteness of the image’s center
t_max (integer) – the iteration’s number of the sequence (zn)
precision (integer) – number of terms in the array (using to build the image)
-
anim_pics_mandel(go_up=True, puiss=2)¶ Shows the Mandlebrot set in 3D. It saves the video in .avi.
- Parameters
go_up (boolean) – type of display, using in mandle_loop function
puiss (integer) – the exponent in the Mandlebrot equation, using in the mandle_loop function
-
anim_puiss_mandel(remove=True)¶ Animates other powers in the Mandeblrot equation.
As the main equation of the Mandelbrot uses a power of 2, we display here the Mandelbrot set for all the integers between 2 and a hundred.
- Returns
successive zoom of the Mandlebrot set
- Return type
Animation / video
-
animate_mandel_plt(x=- 1, y=- 0.3)¶ Zoom in on the Mandlebrot graph.
This animation zooms in on the point (x,y) to see the fractals.
- Parameters
x (float) – coordinate on the real axis of the point to zoom in.
y (float) – coordinate on the imaginary axis of the point to zoom in.
- Returns
the animation of the Mandlebrot’s zoom saved in .avi
- Return type
matplotlib plot
-
disp_mandel()¶ Using the array of the mandlebrot function, this function shows the mandlebrot set.
- Returns
plot the Mandlebrot set
- Return type
matplotlib plot
-
mandel_loop(go_up=True, puiss=2)¶ Determines coordinates of points, in the Mandlebrot set and the speed of divergence.
- Parameters
go_up – type of display, condition to give values in mandel’s array
puiss – the exponant in the Mandlebrot equation
- Type
boolean
- Returns
the Mandlebrot set in colors
- Return type
numpy array
-
mandel_transform(FUN)¶ Determines coordinates of points in the transformation of the Mandelbrot set.
- Parameters
FUN (function) – function that replaces the mandelbrot recursive equation
- Returns
the Mandlebrot set transformed
- Return type
numpy array
-
mandelbrot()¶ Gives a boolean matrix reprensenting the Mandelbrot set.
We affect the value True if the point is in the Mandlebrot set, false otherwise.
- Returns
a matrix indicating whether or not the point is in Mandlebrot set.
- Return type
numpy array
Additional function in the submodule¶
As part of the link with the logistic map, we needed a function that could return a stairs-like data about the different values that would take the map \(z_{n+1}=z_n^2+c\) with different values for \(c\). See the bifurcation video in the gallery for the actual plot.
-
mandel_branch_points(x0, mu, nb_iter=20)¶ Fives the coordinates of Mandlebrot points.
Starting with the coordinate of (x0,0), the function applies the Mandlebrot sequence. Each coordinates is appended in a list, useful to draw stairs of the recursive sequence.
- Parameters
x0 (float) – the starting point included in [0,1]
mu (float) – the common ratio of the Mandlebrot sequence, included in [0,1]
nb_iter (integer) – the number of coordinates put in our final list
- Returns
list of Mandlebrot points coordinates
- Return type
list of tuples
One can use this function to produce the same plot in the top-right of the video in the bifurcation diagram section of the gallery using the code below.
plt.style.use(['ggplot', 'dark_background'])
data = zip(*chaos.mandel_branch_points(0,-1,50))
ax2 = plt.subplot()
x = np.linspace(-2, 1, 400)
line, = ax2.plot([],[], color='red', alpha=1, lw=4)
line.set_data(data)
courbe, = ax2.plot([], [], color='dodgerblue', alpha=1, lw=2)
courbe.set_data(x, x**2-1)
ax2.plot(x, x, color='orange')
plt.show()