cs249 lecture notes, Fall 2001 Week 6, Thursday Quiz Monday on Chapter 5 Schedule exam... October 22 or 25? In-class work: Mandelbrot set based on Willis equation. Willis equation is z^3 - 2z - 5 = 0 Mandelbrot set is all the points in the complex plane that, using Newton's method, converge on a root in an even number of steps. Today we practice incremental programming 1) take the big task and split it into lots of little steps 2) test each step individually 3) assemble gradually For today's example, some of the steps are: 1) Create a file called mandel.m 2) Write function named iterate that takes initial value z0 and uses Newton's method to find a root. 3) Write the top-level function named mandel and use it to test iterate 4) Figure out what we mean by convergence and modify iterate so that it exits the loop early if we achieve convergence. 4a) As an aside, what is the real root of the Willis equation. 5) Modify iterate so that it works with complex numbers. 5a) Find the complex roots. 6) Make iterate return the number of steps rather than the root. 7) Write plotPoint to draw a rectangle at a given location with a given color. What input variables? 7a) Write and test the innards in the high level function. 7b) Figure out what the parameters are and make a function. 8) Draw a row of points, all one color. Parameterize it to control the number of points in the row. 8a) Likely bug here: in order to work correctly, the input variable in plotPoints has to be complex. 9) Draw a grid of points, all one color. 10) Invoke iterate and color each point according to the parity (evenness or oddness) of the number of iterations. function result = mandel2 (n) clf; hold on; f = gcf; set (f, 'DefaultLineMarkerSize', 2); willis (n) function willis (n) coords = linspace (-3, 3, n); for real = coords for imag = coords z = real + i * imag; a = iterate (z); if (a == -1) continue elseif (mod(a,2) == 0) plotPoint (z, 'rs', 'red'); else plotPoints (z, 'bs', 'blue'); end end end axis ([-3 3 -3 3]); function plotPoint (z, format, color) h = plot (z, format); set (h, 'MarkerSize', 2); set (h, 'MarkerFaceColor', color); function result = iterate (z0) z = z0; lastz = z0; for j = 1:100 z2 = z*z;