User Tools

Site Tools


gibson:teaching:spring-2018:math445:lab10

Differences

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

Link to this comparison view

Next revision Both sides next revision
gibson:teaching:spring-2018:math445:lab10 [2018/04/16 18:59]
gibson created
gibson:teaching:spring-2018:math445:lab10 [2018/04/17 06:54]
gibson
Line 10: Line 10:
 Open the file ''​mylife.m''​ and start enter these lines. ​ Open the file ''​mylife.m''​ and start enter these lines. ​
  
-<​code>​ +<​code ​matlab
-function mylife(T) +function mylife(X0,T,N
-if nargin == 0; T = 500; end +   ​if nargin == 2; N = 20; end    
 +   if nargin == 1; T = 100; end 
 </​code>​ </​code>​
  
Line 18: Line 19:
 of the code? of the code?
  
-**3.** Next set up the initial layout ​for the game of life on a  +**3.** Next set up the grid and assign ​initial layout ​to the center
-a 50 x 50 gridThis initial condition leads to some pretty interesting behavior!+
  
-<​code>​ +<​code ​matlab
-N=50+  ​[m,​n] ​size(X0)   % get size of initial condition ​   
-X=sparse(N,​N);​+   N2 = floor(N/​2); ​   % approx center of grid 
 +   X=sparse(N,​N); ​     % allocate sparse matrix 
 + 
 +   ​X(N2:​N2+m-1,​ N2:N2+n-1) = X0;  % assign X0 to center of X 
 +</​code> ​  
  
-N2 = N/2; 
-X(N2-1,​N2-1)=1;​ 
-X(N2-1,​N2)=1;​ 
-X(N2,​N2-1)=1;​ 
-X(N2,​N2+1)=1;​ 
-X(N2+1,​N2+1)=1;​ 
-X(N2+1,​N2+2)=1;​ 
-</​code>​ 
  
  
Line 86: Line 82:
  
  
-**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. On your first runs, try using  
-can. Save this code as ''​mylife.m''​ to turn in. + 
 +<code matlab>​ 
 +T = 100; 
 +N = 20; 
 +X0 = [ 1 1 0 0; 1 0 1 0; 0 0 1 1]; 
 +</​code>​ 
 + 
 +That should lead to some pretty intersting behavior. If you get errors, ​debug your code until it runs correctly. Save this code as ''​mylife.m''​ to turn in. 
  
  
gibson/teaching/spring-2018/math445/lab10.txt · Last modified: 2018/04/19 08:11 by gibson