User Tools

Site Tools


gibson:teaching:fall-2012:math445:lab7

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gibson:teaching:fall-2012:math445:lab7 [2012/10/22 20:58]
gibson
gibson:teaching:fall-2012:math445:lab7 [2012/10/31 19:34] (current)
gibson
Line 2: Line 2:
  
  
-**1.** Read Chapter ​of the Moler text, and think through how the provided+**1.** Read [[http://​www.mathworks.com/​moler/​exm/​chapters/​life.pdf|Chapter ​12 of the Moler text]] 
 +and think through how the provided
 code updates the very first and last cells in the grid. What specific ​ code updates the very first and last cells in the grid. What specific ​
 line or lines of code are responsible for these "​boundary conditions"?​ line or lines of code are responsible for these "​boundary conditions"?​
Line 10: Line 11:
 **2.** We are going to create our own code for the game of life and use a **2.** We are going to create our own code for the game of life and use a
 different approach based that does not allow anything to live on different approach based that does not allow anything to live on
-borders of the domain. We will let our board be 100x100 ​grid. Start a+borders of the domain. We will let our board be 50x50 grid. Start a
 new script file, and start it with the lines  new script file, and start it with the lines 
  
Line 38: Line 39:
 **4.** Initialize to zero a variable to count the discrete time ''​t''​ and  **4.** Initialize to zero a variable to count the discrete time ''​t''​ and 
 then start a loop that stops after ''​T''​ iterations or when everything ​ then start a loop that stops after ''​T''​ iterations or when everything ​
-is dead (Hint: what would ''​max(max(L))''​ return? What does the command ​+is dead (Hint: what would ''​max(max(L))''​ return?What does the command ​
 ''​break''​ do?). ''​break''​ do?).
  
-**5.** Implement the code given in Chapter 9 that will update the ''​L''​ matrix  +**5.** Implement the code given in the Moler text that will update the ''​L''​ matrix  
-with periodic ​boundary conditions. Later we will change ​it to not be periodic.+with boundary conditions ​that repeat the border cells. Later we will change ​the  
 +boundary conditions ​to enforce zeros on all boundaries.
  
 **6.** In order to plot the figure, look up the function ''​find''​ in the help **6.** In order to plot the figure, look up the function ''​find''​ in the help
Line 62: Line 64:
 your plots look better. If you use ''​pause(0.5)'',​ Matlab will pause  your plots look better. If you use ''​pause(0.5)'',​ Matlab will pause 
 just half a second, instead of waiting for you to hit return. just half a second, instead of waiting for you to hit return.
 +
 +**Better idea:** put the ''​figure(1)''​ command outside the for-loop, in the
 +initialization portion of your code.
  
 **7.** You should now be able to run the code. If not debug it so that you **7.** You should now be able to run the code. If not debug it so that you
-can. Verify that the boundaries are periodic and wrap from one edge +can. 
-of the screen to the other.+
  
 **8.** The following code will kill anything on a certain boundary **8.** The following code will kill anything on a certain boundary
Line 87: Line 91:
 might be easier) is plotted and then ''​hold off''​ after the last point is might be easier) is plotted and then ''​hold off''​ after the last point is
 plotted. plotted.
 +
 +**Better idea**: Calculate four sparse matrices L1, L2, L3, L4, which are nonzero ​
 +wherever L is live and has 1, 2, 3, and 4 or more live neighbors, respectively. ​
 +Then plot all the nonzero entries of L1 with red, of L2 with blue, L3 with green, ​
 +and L4 with ''​[0.5 0 0.5]''​.
  
 **10.** Change the orange color in the above plots to purple. What is the  **10.** Change the orange color in the above plots to purple. What is the 
Line 106: Line 115:
  
  
-**14.** ​Turn in your completed ​code and the answers ​to the above questions.+**14.** ​(bonus) Modify ​your code to have periodic boundary conditions instead of zeros  
 +on the bordersDoes this change the long-term behavior of the system substantially?​
  
 +**15.** Turn in your completed code and the answers to the above questions.
gibson/teaching/fall-2012/math445/lab7.1350964692.txt.gz · Last modified: 2012/10/22 20:58 by gibson