|CS 107 - Introduction to Scientific Computation
1. Julia Set Fractals: For this exercise, we will modify the Mandelbrot Set exercise (developed in class) to allow exploration of Julia Set Fractals. Recall that, for the Mandelbrot iteration, we pick an initial z0 = 0, and iterate zt+1 = zt2 + c until abs(z) > 2 or we reach some maximum number of iterations. We then return the number of iterations that abs(z) stayed within 2. This is repeated for a lattice of c values on the complex plane, and we color plot the returned iteration values to see a representation of the Mandelbrot Set and surrounding points diverging to infinity at different rates.
For each point c in our Mandelbrot Set plot, there is a corresponding
Julia Set. (Here is
an applet to explore
both the Mandelbrot Set and Julia Sets associated with a selected point c.)
We compute our plot data using a very similar process to the Mandelbrot Set
exercise. First, we choose the point c from our Mandelbrot Set.
This means we need to add a new, first argument c to
function drawJulia(c, realMin, realMax, imagMin, imagMax, pts, iters). The
matrix of iterations we compute (S in the in-class example) should be the return
juliaIterate.m, we will also add this c as a fixed first parameter, the same for
each call, letting c2 be the complex point we're varying over the plot:
function i = juliaIterate(c, c2, niter). For the Julia Set iteration, we
initialize z0 = c2, and iterate zt+1 = zt2
- c until abs(z) > 2 or we reach some maximum number of iterations. We
then return the number of iterations that abs(z) stayed within 2.
Here are some example inputs you might like to try:
>> drawJulia(.73 + .2145i, -1.5, 1.5, -1.5, 1.5, 1000, 200) >> drawJulia(.73 + .2145i, -.5, .5, -.5, .5, 1000, 200) >> drawJulia(.73 + .2145i, -.1, .1, -.1, .1, 1000, 200) >> drawJulia(.219 + .77i, -1.5, 1.5, -1.5, 1.5, 1000, 200) >> drawJulia(.219 + .77i, -.5, .5, -.5, .5, 1000, 200) >> drawJulia(.219 + .77i, -.1, .1, -.1, .1, 1000, 200)
You may also enjoy other color schemes by entering the command
MAP is one of
2. Nested Loops: Exercise 8.1. Your function should be in file
3. Making Change: Exercise 8.9. Your function should be in file
Clarification: The two parameters for makechange are
At no point in your code should you be dealing with strings (e.g. ‘usdenoms’).
Here are some more example transcripts to show how versatile the behavior should be:
>> makechange(12.34, [10 5 1 .5 .25 .10 .05 .01]) ans = 1 0 2 0 1 0 1 4 % Note: This means 1 * 10 + 0 * 5 + 2 * 1 + … etc.. Each vector position in the return value corresponds to the number of denominations in the same position of the 2nd input parameter (denominations). >> makechange(12.34, [8 4 2 1 .5 .25 .125 .0625]) ans = 1 1 0 0 0 1 0 1 >> makechange(12.34, 2.^(3:-1:-5)) ans = 1 1 0 0 0 1 0 1 1 >> makechange(12.34, 3.^(3:-1:-5)) ans = 0 1 1 0 1 0 0 0 2
Final note: Floating point errors can give some unexpected results in the number of the last (lowest) denomination. Use rounding (round) when dividing the lowest denomination into the smallest remaining amount; use flooring (floor) in all other cases.
4. Perfect Numbers: Exercise 8.17. Your function should be in file
function list = getPerfectNums(maxNum) and
maxNum is the upper limit of your
perfect number search,
list is an ascending list of perfect numbers. NOTE 1: There is an error in the text. The text reads "A perfect number is a number whose prime factors (including 1) add up to the number itself." Instead, it should read "A perfect number is a number whose positive divisors (including 1 and excluding itself) add up to the number itself. NOTE 2: Do not use Euclid's formula for the first four perfect numbers. Test each integer from 1 to