102 lab9

Notes on Lab #9

For this lab, you will explore the Spreading of Fire Model using Matlab. In the process, you will learn a little about Matlab and software development. You should be able to do the lab on the Mac, but if you run into trouble let me know right away. You can also do it on the Stable (Science Application / Morgan), in which case things might work a bit differently – again, just let me know if you hit a wall.

Getting Started

To get started, download and unzip this file containing the general cellular automaton simulator, and this file containing functions specific to this lab. Copy or move the contents of the former (ca) into the latter (lab09). Then open the lab09 folder, right-click on the init.m file, and choose Matlab as the program to use for opening it. This will launch Matlab and open the init file for you. Clicking Run (the green arrow) at the top of Matlab, you will be asked whether you want to change folders, which you do, so click Change Folder. At the bottom of Matlab you will then see an error in red. Now you are ready to begin coding.

Your first task will be to modify this file (init.m) and the file update.m to get the spreading-of-fire CA working. To get started, do the following at the Matlab prompt:

>> ca(20)

The cellular automaton program will pop up with an empty grid and allow you to step it or run it at a chosen speed. Nothing interesting will happen, because you haven’t completed the project yet: the functions are currently “stubs” that you will fill in. Note that once you’ve typed a command, you don’t need to re-type it; you can retrieve it (and other previous commands) via the ↑ key in the lower-right area of the keyboard.

Try to avoid clicking inside the grid, or you will be asked to enter a value (an advanced feature for extra credit later, perhaps). If this happens, just close the figure, hit CTRL-C and start over.

In the Matlab editor open init.m and underneath the XXX add some code to initialize the grid. You will find these slides (starting at #16) useful for both this function and the update function. (Don’t type; just copy-and-paste. Hit CTRL-A (APPLE-A on Mac) then CTRL-I (APPLE-I) periodically to make everything line up nicely.)

You should now be able to see an initial state that will not change when you step or run. To finish this part, add one or more lines of code in the appropriate places in update.m as well. To make your code a little easier to read, I have included some directional functions (north, south, east, west) that can replace the somewhat confusing calls to circshift in the update function.

<h2″>Running the Simulation Once you have the CA working, you should use it to answer the following questions, by running each simulation several times and observing the end result. The grid may go blank on the last step, so you’re better off stepping through than running all at once with Go. As with Vensim, make sure to hit save on your file before running the model.</h2″>

  1. What happens when probBurning is almost 0, probLightning = 0, probImmune = 0 ?
  2. What happens when probBurning = 0, probImmune = 0, probLightning = 0.8 ?
  3. What happens when probBurning = 0, probLightning = 0 ?

You can report your results qualitatively; i.e. a description of what happens in ordinary language, without numbers or graphs, but do mention what sized grid you used and how many steps you ran. If you have time, think up some other scenarios to try out, and report your results. In addition to modifying the parameters in the Matlab code, you can modify the grid interactively by right-clicking to remove a tree, or left-clicking to set a value (0=no tree; 1=tree; 2=fire). Can you make a firebreak? When you’re finished, upload your PDF writeup to the turnin folder. (No need to upload your Matlab files, unless you made some interesting modification to the code.)