Difference between revisions of "Mandelbrot set"

From ScienceZero
Jump to: navigation, search
(New page: The formula for the mandelbrot set is: :Z = Z<sup>2</sup> + C C is a point in the complex plane where i is on the vertical axis and real numbers are horizontal. A complex number has the f...)
 
Line 7: Line 7:
 
:(Zr+Zi) = ((Zr+Zi) * (Zr+Zi)) + (Cr+Ci)
 
:(Zr+Zi) = ((Zr+Zi) * (Zr+Zi)) + (Cr+Ci)
 
[http://mathworld.wolfram.com/ComplexNumber.html Complex addition] has the form:
 
[http://mathworld.wolfram.com/ComplexNumber.html Complex addition] has the form:
:(a+bi)+(c+di) = (a+c)+i(b+d)    ()
+
:(a+bi)+(c+di) = (a+c)+i(b+d)
 
[http://mathworld.wolfram.com/ComplexNumber.html Complex multiplication] has the form:
 
[http://mathworld.wolfram.com/ComplexNumber.html Complex multiplication] has the form:
 
:(a+bi)*(c+di) = (ac-bd)+i(ad+bc)
 
:(a+bi)*(c+di) = (ac-bd)+i(ad+bc)
Line 23: Line 23:
 
If Z escapes to infinity at any time during the iterations then C is outside the mandelbrot set.
 
If Z escapes to infinity at any time during the iterations then C is outside the mandelbrot set.
 
When C is confirmed to be outside or inside we plot a corresponding white or black pixel at coordinate C. After N iterations we give up to make sure the program finishes.
 
When C is confirmed to be outside or inside we plot a corresponding white or black pixel at coordinate C. After N iterations we give up to make sure the program finishes.
 +
  
 
  For Ci = -2 To 2 Step 0.01
 
  For Ci = -2 To 2 Step 0.01
Line 45: Line 46:
  
  
[[Categorey:Computing]]
+
[[Category:Computing]]

Revision as of 16:46, 31 January 2007

The formula for the mandelbrot set is:

Z = Z2 + C

C is a point in the complex plane where i is on the vertical axis and real numbers are horizontal. A complex number has the form of x+iy where x and y are real numbers and i is the sqare root of -1. so the formula can also be written:

(Zr+Zi) = ((Zr+Zi) * (Zr+Zi)) + (Cr+Ci)

Complex addition has the form:

(a+bi)+(c+di) = (a+c)+i(b+d)

Complex multiplication has the form:

(a+bi)*(c+di) = (ac-bd)+i(ad+bc)

so

(Zr+Zi * Zr+Zi) = (Zr*Zr-Zi*Zi)+i(Zr*Zi+Zi*Zr)

and

(Zr*Zr-Zi*Zi)+i(Zr*Zi+Zi*Zr) + (Cr+Ci) = (Zr*Zr-Zi*Zi)+Cr+i(Zr*Zi+Zi*Zr)+Ci

that gives us

Zr = (Zr*Zr-Zi*Zi)+Cr
Zi = (Zr*Zi+Zi*Zr)+Ci

we must remember to use temporary values to calculate Zr so it does not affect the result of Zi.

Z = C when we enter the loop. If Z escapes to infinity at any time during the iterations then C is outside the mandelbrot set. When C is confirmed to be outside or inside we plot a corresponding white or black pixel at coordinate C. After N iterations we give up to make sure the program finishes.


For Ci = -2 To 2 Step 0.01
    For Cr = -2 To 2 Step 0.008
        Zr = Cr
        Zi = Ci
        For i = 1 To 100
            Zrt = (Zr * Zr - Zi * Zi) + Cr
            Zi = (Zr * Zi + Zi * Zr) + Ci
            Zr = Zrt
            If (Zr * Zr + Zi * Zi) > 4 Then Exit For
        Next i
       
        If i = 101 Then
            complexPlane.PSet (Cr, Ci), RGB(0, 0, 0)        'Looks like we are inside
        Else
            complexPlane.PSet (Cr, Ci), RGB(255, 255, 255)  'Infinity
        End If
   
    Next Cr
Next Ci