extending mandelbrot to generate julia

2020-03-31 06:57发布

问题:

working on a project requiring me to use same code ,note in the same file to generate mandelbrot set and julia sets ,i hav a working mandelbrot set but can see how to extend to julia set using same code. maybe am not getting the differences between ? can anyone elaborate

import numpy as np
import matplotlib.pyplot as plt
import math



def Mandelbrot(zmin, zmax, m, n, tmax=256):

    xs = np.linspace(zmin, zmax, n)
    ys = np.linspace(zmin, zmax, m)
    X, Y = np.meshgrid(xs, ys)


    Z = X + 1j * Y
    C = np.copy(Z)
    M = np.ones(Z.shape) * tmax

    for t in xrange(tmax):
        mask = np.abs(Z) <= 2.
        Z[ mask] = Z[mask]**2 + C[mask]
        M[-mask] -= 1.
    return M

list=Mandelbrot(-2,2,500,500)
plt.imshow(list.T, extent=[-2, 1, -1.5, 1.5])
plt.gray()
plt.savefig('mandelbrot.png')

回答1:

The Mandelbrot set is a special set in terms of Julia sets, some documentation writes that the Mandelbrot set is the index set of ALL Julia sets (there is one and only one index set - the Mandelbrot - and there are infinite number of Julia sets.)

When you calculate a point on the Mandelbrot set and iterate over z^2 + c, this c takes the same value as the point you try to decide if it is part of the map or not. This c will change if you go to the next point (that is how you did in your calculation).

In other words you have a value that is constant while you go through the iteration but will change for every different point.

When you calculate Julia sets, the calculation is 99.9% the same except you have to use a c value that is constant during the entire calculation not just for a single point. And that is why it is not named as c to avoid confusion, but usually k.

Now if I confused you enough, the solution is dead simple. You have to change this:

Z[ mask] = Z[mask]**2 + C[mask]

to this:

Z[ mask] = Z[mask]**2 + (-0.8+0.156j)

Check the same set here: http://en.wikipedia.org/wiki/File:Julia_set_camp4_hi_rez.png



回答2:

In Mandelbrot fractal the z value is 0 in the start of the iteration and in the Julia fractal it uses a different value from the screen coordinate and a fixed complex number.