Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Law of large numbers wikipedia , lookup
Hyperreal number wikipedia , lookup
Large numbers wikipedia , lookup
Georg Cantor's first set theory article wikipedia , lookup
Real number wikipedia , lookup
Mathematics of radio engineering wikipedia , lookup
Fundamental theorem of algebra wikipedia , lookup
Collatz conjecture wikipedia , lookup
Elementary mathematics wikipedia , lookup
-1 -0.8 -0.6 -0.4 -0.2 0 D A 0.2 0.4 0.6 0.8 1 -1.5 C -1 B -0.5 0 0.5 Matlab Deliverable 1: The Mandelbrot Set The Mandelbrot set is the most famous fractal in the world β images of the Mandelbrot set can be found everywhere, and itβs likely that an image of the Mandelbrot set comes to mind when the word fractal comes up. Like most fractals, the Mandelbrot set is computed using a few very simple rules which can easily be programmed in Matlab. The fundamental rule of the Mandelbrot set can be stated mathematically as follows: π§π+1 β π§π2 + π (1) where c is a complex number and z0 = 0. The rule is a method for generating a series of numbers, where each number in the sequence depends upon the preceding number. For some values of c, the sequence converges, and for other values it βblows upβ. If a value of c results in a converging series, it is said to be part of the βMandelbrot setβ. In the figure above, the values of c that are in the Mandelbrot set are plotted in gray, while those that are not are plotted in white. The real part of c is plotted along the x axis and the imaginary part is plotted along the y axis. To see this rule in action, let us take a simple example: c = 0 + 0j, which is the point A in the figure above. Following the rule gives π§1 = 0 π§2 = 02 + 0 π§3 = 02 + 0 = 0 ππ‘π. (2) 1 Clearly, this sequence converges to zero, so it is part of the set. Now try another example: c = -1 + 0j (the point D in the figure above). π§1 = β1 π§2 = (β1)2 β 1 = 0 π§3 = 02 β 1 = β1 π§4 = (β1)2 β 1 = 0 π§5 = 02 β 1 = β1 (3) This sequence is bouncing around between -1 and 0, but at least it isnβt blowing up to infinity! Thus, the point D is also in the Mandelbrot sequence. Now examine the point C in the figure, which is at c = -1 + 1j. To compute the sequence, it is easiest to use Matlab. First, type c = -1 + 1j at the command prompt. Matlab will answer with c = -1.0000 + 1.0000i proving that it understands complex numbers. Now type the first three numbers in the sequence z0 = 0 z1 = z0^2 + c z2 = z1^2 + c and Matlab will respond with z2 = -1.0000 - 1.0000i So far, so good. But if you keep adding numbers to the sequence, youβll find that z6 = -5.2570e+03 + 1.0011e+04i In other words, the sequence is blowing up, rather quickly! By the sixth number in the sequence the magnitude is over 11,000, and it wonβt take long before we reach the maximum number allowable in Matlab. Thus, the point C is not part of the Mandelbrot set, and is plotted in white. Finally, let us examine the point B, which is quite interesting. It lies at c = 0 + 1j, which is surrounded by white in the figure. At first glance, we would guess that B should blow up and not be part of the set, since the points around it are also not part of the set. However.... z2 z3 z4 z5 z6 = -1.0000 + 1.0000i = 0.0000 - 1.0000i = -1.0000 + 1.0000i = 0.0000 - 1.0000i = -1.0000 + 1.0000i This sequence bounces around between -1+1j and 0-1j, and does not blow up, thus it is part of the Mandelbrot set and is rendered in gray. This is what makes the set so interesting β there are βislandsβ of the set surrounded by points that blow up. If we zoom in on this point, weβll find that there are shapes similar to the original βcardioidβ shape that emerge at ever smaller scales. This βself-similarityβ is what makes the Mandelbrot set a fractal. 2 The Challenge: Plot the Mandelbrot Set Create an algorithm that determines whether a given complex number, c, converges within a reasonable time. The easiest way to determine convergence is to check whether the magnitude of z is less than 2 at a given iteration. If it is greater than 2, the sequence is guaranteed to blow up a few iterations later. Each value of c corresponds to a pixel on the plot β the x coordinate of the pixel is the real part of c and the y coordinate is the imaginary part. If c is not part of the set, plot a white pixel, and if it is part of the set, plot a black pixel. 1. Write a Matlab program that plots the Mandelbrot set in the range (xβ -2 : 1) (yβ -1 : 1). The plot should be 601 x 401 pixels in size. 2. Write a Matlab program that plots the Mandelbrot set in the range (xβ -0.05 : -0.01) (yβ 0.77 : 0.81). The plot should be 501 x 501 pixels in size. Use the imshow command to plot your image and set the maximum number of iterations for each pixel to 200. 3. Bonus β extra credit! Produce the plots given above in color, with the color of each pixel dependent upon the number of iterations it takes for the sequence to βblow upβ. Appendix: A Few Words about Complex Math While Matlab can store and manipulate complex numbers, your program will be more efficient if you stick with real variables. For a given step in the sequence we must calculate z2, where z is a complex number. Let π§ = π + ππ (4) π§ 2 = (π + ππ)(π + ππ) = π2 + 2πππ β π 2 (5) Then If the complex number under evaluation is π = π₯ + ππ¦ (6) π§ 2 + π = π2 β π 2 + π₯ + π(2ππ + π¦) (7) ππ+1 = ππ2 β ππ2 + π₯ (8) ππ+1 = 2ππ ππ + π¦ (9) Then That is, the new real part is and the new imaginary part is 3 Finally, the magnitude of the complex number is given by |π§| = βπ2 + π 2 (10) For example, let us examine the point c = -1 + 1j. π§0 = β1 + 1π π§1 = [(β1)2 β 12 β 1] + [2(β1)(1) + 1]π = β1 β 1π π§2 = [(β1)2 β (β12 ) β 1] + [2(β1)(β1) + 1]π = β1 + 3π π§3 = [(β1)2 β (3)2 β 1] + [2(β1)(3) + 1]π = β9 β 5π π§4 = [(β9)2 β (β5)2 β 1] + [2(β9)(β5) + 1]π = 55 + 91π π§5 = [(55)2 β (91)2 β 1] + [2(55)(91) + 1]π = β5257 + 10011π (11) These are the same numbers we calculated earlier using Matlab. 4