Code mandelbrot set

0

I am studying a specific code of the mandelbrot set (equation with complex numbers) focusing on object-oriented programming. However, there is a specific part that I did not understand from the code, as below:

columns = 2000

rows = 2000

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] = mset(Re, Im, 200)

Below is the complete code:

import numpy

from numba import autojit

import matplotlib.pyplot as plt

@autojit

def mset (Re, Im, max_inter):

        c = complex (Re, Im)
        z = 0

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

rows = 2000

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] = mset(Re, Im, 200)

plt.figure(dpi=100)

plt.imshow(result.T, cmap='hot', interpolation='bilinear', extent=[-2, 1, -1, 1])

plt.xlabel('Real')

plt.ylabel('imagin')

plt.show()
    
asked by anonymous 02.06.2018 / 16:16

1 answer

0

The code highlighted in the question runs through a space in the complex plane to check whether or not each point belongs to the Mandelbrot set.

Initially, the code defines an array to store the test result of each point in the plane (in question, defined with size 2000x2000):

result = numpy.zeros([rows, columns])

In the sequence, there are 2 loopings that run through the entire (real x imaginary) space.

The range is defined by the linspace() function, which generates num numbers within that range:

# Looping da parte real, composto de 2000 samples no intervalo de -2.0 a 1.0
for row_index, Re in enumerate(numpy.linspace(-2, 1, num=rows)):

    # Looping da parte imaginária, composto de 2000 samples no intervalo de -1.0 a 1.0
    for column_index, Im in enumerate (numpy.linspace(-1, 1, num=columns)):

The loopings will generate the test points.

Example: (-2.0,-1.0), (-2.0,-0.99)...(-1.99,-1.0),(-1.99,-0.99)...... até (1.0,1.0)

Within the looping and for each point, the mset function calculates whether or not the point belongs to the Mandelbrot set and returns the number of iterations necessary to determine this relevance.

This result is stored inside the array result :

result[row_index, column_index] = mset(Re, Im, 200)

The other commands plot the result and display the graph of the array result :

Althoughmentionedinthequestion,thisprogramdoesnotcontemplateconceptsof orientation to object .

More information at: Wikipedia - Mandelbrot Set

    
03.06.2018 / 01:21