Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 71Applying Matlab 21-27-20102Opening Discussion■What did we talk about last class?■Do you have any questions about the reading?3Control Flow Constructs■Last time we looked at the for loop. We also have the following:While loopIf statements – includes if, else, end, and elseif.Switch-case – allows cases with multiple expressions and otherwise clause.Try-catch blocks for error handling. Variable lasterr gives information about the last error.■In general you can get away with only using loops and the if conditional. Switch is occasionally helpful and the try-catch is nice in situations where something might go wrong.4Examples of Control Flow■Write a loop that will do a Mandelbrot check for a single point. Have it loop until zn has a magnitude greater than 2 or you get through 100 iterations.5Functions■Matlab functions are a bit different from what you are used to in other languages. They can take a variable number of arguments and return a variable number of arguments.■To return a value, we set a variable with the name specified on the first line of the function to the value we want to return. That is what will be returned when the function terminates.■You can also have local functions or nested functions. When either of these is used the main function must be terminated with end.■Function handles are also discussed in the book and they are worth noting.6Writing a Function■We have our Matlab code to do the iteration for a single pixel of the mandelbrot set. Now make an m-file and put that code into the m-file as a function that takes a point and returns how many iterations it went.■Let's try to write code that will plot up a full Mandelbrot set for us.■How could we do this better? Generally you want to avoid explicit loops in Matlab. What is the fewest number of loops we could get away with to make a Mandelbrot?7Closing Remarks■Remember to submit assignment #2
View Full Document