I'm now tryin to graph Mandelbrot Set. For those who may not know what this is, it is a fractal defined by a quite simple recursion. Mandelbrot Set is a set of complex numbers (i.e., of the form a+bi, i=sqrt(-1)) represented in a complex plane, obeying the following "law":
A complex number c belongs to the Mandelbrot Set if the recursion
(Please, interpret _ as subscript. Or visit wikipedia, that would be easier though xD )
does Not tend to reach infinity, or by other words, remains bounded.
Then, just plot the real and imaginary parts of c, and there you have it!
I've checked an older thread from 2009 about mandelbrot, but i didnt get clarified.
I have made my own Mandelbrot plotting program, but i think it runs a bit slowly. Ive seen that this website holds a Mandelbrot program, but the description says it takes a lot of time to finish.
It would be of great help if you took a look at my code and pointed some optimization solutions:
Some concepts: cardioid is the bulb at the right, the largest one; the period-2 bulb (or 2nd bulb, as ill call it) is the 2nd largest and it is at the left of the cardioid. The most part of these sectors can be represented by the equations of the cardioid and the circle. For more info, visit wikipedia, the place from where i got all this stuff and equations.
In fact, Mandelbrot Set requires an infinite number of iterations to be fully correct, but we need to make it quick. So, as you can observe in a scaled Mandelbrot plot, the plotted zone is limited to a circle of center (0,0) and radius 2. Meaning, we can use a condition like that to define "infinity", formally called "escape condition". That's because if you ever get a point in the recursive operation outside this circle, you know the next point will begin to "escape" from (0,0), thus tending to infinity. Our escape condition will be 2<abs(Z, with 2 being the limit for the distance between (0,0) and Z, and abs(Z calculating that distance.
// X - x-coordinate of the center of the screen // Y - y-coordinate of the center of the screen // Z - Zoom as a temporary variable. When finished with putting the graph screen in order, it'll be used as z in the recursion // M - No. of interations to verify the recursion // N - Used as a natural number, going from 1 to M in order to stop the recursion when N=M // B - Temporary, just to put the graph screen in order // C - The complex number to be tested // R - The real part of C // I - The imaginary part of C. (Not to be confused with i=sqrt(-1 Input X Input Y Input Z Input M 3/(2Z->B X-B->Xmin X+B->Xmax 1/Z->B Y-B->Ymin Y+B->Ymax // This stuff is just to put the graph screen in order, according to the inputs For(R,Xmin,Xmax,(delta)X For(I,Ymin,Ymax,(delta)Y Pt-Change(R,I // to keep a track of the point being checked (R-1/4)^2+I^2 I^2>4Ans(Ans+(R-1/4 // to check if it belongs to the cardioid. Wikipedia If Ans Goto 0 // if it does, jump the Repeat loop (R+1)^2+I^2<1/16 // to check if it belongs to the 2nd bulb. Wikipedia If Ans Goto 0 // if it does, jump the Repeat loop Delvar ZDelvar N R+Ii->C // our complex number to be tested Repeat N=M or Ans // checks for our "infinity" N+1->N Z^2+C->Z 2<abs(Z // escape condition. If true, will return 1 to the current Repeat loop, and also return 1 to the next Repeat loop End If Ans Pt-Change(R,I // the point being currently checked was turned on. If it doesnt belong to madelbrot set, it turns off again. Meaning, if it belongs, it wont turn off Lbl 0 End End
For convenience reasons, i advide inputing X=-1/2, Y=0, Z=1 and M=20. This way, you'll be able to graph the entire fractal and visualize it easily.
It would be really helpful if you could help me making it faster, as ive checked on its speed and it took 28min (!) to finish.