Fractal Assignment In Matlab Complex Numbers 5 i
Fractal Assignment In Matlab
Complex Numbers • 5 i 3+4 i 4 i 5 Imaginary 3 i 2 i 1 i 0 i -1 -0. 5 0 0. 5 1 1. 5 Real 2 2. 5 3 3. 5 4
Julia Set abs(z) • Iteration Number
Julia Set abs(z) • Iteration Number
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. Imaginary Iterations 250 200 c = -0. 795 + 0. 18 i 150 100 Real 50 0
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 -2 i to +2 i 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. 18 i; • 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 map • e. g. Ømap = colormap(‘hot’);
Julia Set • 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*n • z = 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 = z 2 + 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; Ø end • Step 6: Save the number of iterations in the Iter matrix • e. g. • Iter(ind) = iter; • Step 7: end the for loop • Step 8: Display the image • e. g. Ø figure; imshow(uint 8(Iter-1)); colormap(map);
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.
- Slides: 8