In Matlab Complex Numbers In mathematics This means that In Matlab i means the same thing Try typing i 2 in the Matlab command window A number with i in it is called a complex number ID: 594310
Download Presentation The PPT/PDF document "Fractal Assignment" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Fractal Assignment
In MatlabSlide2
Complex Numbers
In mathematics
.
This means that .In Matlab, i means the same thing.Try typing i^2 in the Matlab command window.A number with i in it is called a “complex number.”Complex numbers can be mixed with real numbers, for example: 3 + 4i.This describes a point in the complex plane that is 3 to the right on the real line, and 4 up on the imaginary line, as shown in the diagram to the right.It’s vector length is: .Matlab computes the vector length of complex numbers using abs.In the Matlab command window try typing:abs(3+4i)
-1
-0.5
0
0.5
1
1.5
2
2.5
3
3.5
4
Real
-1
i
0
i
1
i
2
i
3
i
4
i
5
i
Imaginary
3+4
i
5Slide3
Julia Set
Suppose now that we take some number z (e.g. z = -
i
) and a constant c (e.g. c = i) apply the following rule:z = z2 + cz = -1 + iHere, abs(z) = 1.4142.Next, we take our new value of z and put it back into our original equation:z = z2 + cz = -iNow, abs(z) = 1.In this case, the value of abs(z) remains forever bounded between 1 and 1.4142.
Iteration Number
abs(z)Slide4
Julia Set
Suppose instead we start with z= 1 (keeping c =
i
).z = z2 + cz = 1+iAgain, abs(z) = 1.4142 .Now we iterate againz = z2 + cz = 0+3iNow, abs(z) = 3.Here, the magnitude of z quickly approaches infinity.
Iteration Number
abs(z)Slide5
Julia Set
The Julia set is defined as the set of complex conjugates that when subjected to
z = z
2 + c remain bounded within a given range and to not go to infinity.RealImaginary
0
50
100
150
200
250
Iterations
c =
-0.795 + 0.18
iSlide6
Julia Set
Write a Matlab script that creates a Julia set image.
Step 1: Set up a grid of points over the real/imaginary plane going from -2 to +2 along the real line and -2i to +2i along the imaginary line.
e.g. n = 100;[R,I] = meshgrid(linspace(-2,2,n));Step 2: Pick a value for the constant c.e.g. c = -0.795 + 0.18i;Step 3: Initialize a matrix to hold the number of iterations for each R,I combination.e.g.Iter = zeros(n,n);Step 4: Pick a colour mape.g.map = colormap(‘hot’);Slide7
Step 5: Set up a
for
loop that goes from 1 to n*n, where on each cycle, z is set to a new combination of R and I.
e.g. for ind = 1:n*nz = R(ind) + I(ind)*i;Step 5.1: within this for loop, initialize an iteration counter, and set up a while loop that keeps calculating z = z2 + c while abs(z) is less than 2 and the number of iterations is less than the number of rows in the colour map.e.g.iter = 0;while abs(z)<2 & iter<=size(map,1) & ~isinf(abs(z))z = z^2 + c;iter = iter + 1;endStep 6: Save the number of iterations in the Iter matrixe.g.Iter(ind) = iter;Step 7: end the for loopStep 8: Display the imagee.g. figure; imshow(uint8(Iter-1)); colormap(map);Julia SetSlide8
Julia Set
Once you’ve written your script and can generate a Julia set image, try different values for c.
Try different colour maps.
Which one is the most beautiful?Pick your favourite image and bring it to our next workshop to share with everyone.