213 - A6 - Linear Dynamical System

239 days ago by Professor213

This worksheet allows the user to input a transition matrix and initial vector and then iterate for any desired number of time steps.

John Travis

Mississippi College

%hide %auto N=2 print html("<font size=+2 color=blue>Enter N below. Click Update when you are finished.</font>") @interact def _(Size_of_System=[2..10]): global N N = Size_of_System html("<font size=+2 color=blue>The size of your square system will be "+str(N)+"$\\times$"+str(N)+"</font>") html("<font size=+2 color=blue>Evaluate the cell below and enter the system data.</font>") 
       
Enter N below. Click Update when you are finished.
Size_of_System 

Click to the left again to hide and once more to show the dynamic interactive window

print html("<font size=+2 color=blue>Enter the transition matrix for your dynamical system and the starting state below. You can tab to navigate between cells. Click Update when you are finished.</font><p>") @interact def _(Transition_Matrix=zero_matrix(QQ,N,N),Initial_State=zero_matrix(QQ,N,1),auto_update=False): global A global b A = Transition_Matrix b = Initial_State 
       

Click to the left again to hide and once more to show the dynamic interactive window

%auto print 'Using the data' show(A) b0 = copy(b) show(b0) 
       
Using the data
Traceback (click to the left of this block for traceback)
...
NameError: name 'A' is not defined
Using the data
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_4.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cHJpbnQgJ1VzaW5nIHRoZSBkYXRhJwpzaG93KEEpCgpiMCA9IGNvcHkoYikKc2hvdyhiMCk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpO1IAyH/___code___.py", line 3, in <module>
    show(A)
NameError: name 'A' is not defined

Assignment: For a given dynamical systems problem (should be stated here):

  • Perform one step below to make certain your dynamical system is working properly
  • Perform a small number of steps (say 5-10) and notice any drastic changes in any of the various populations
  • Perform a large number of steps and notice whether the populations tend to stabilize about a given value.
  • Write up your results in a text cell below. Be certain to cut-and-paste the transition matrix and initial values into another cell for me to see what you used. A copy is output below the interactive cell below for you to grab and save.
       
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
[0 0 0]
%auto @interact def _(steps = slider(1,100,1,1)): global A,b b = copy(b0) terms = range(b.nrows()) colors = rainbow(b.nrows()) P = Graphics() for term in terms: P += point2d((0,b[1][0]),color=colors[term]) for k in range(steps): b = A*b for term in terms: P += point2d((k,b[term][0]),color=colors[term],size=30) show(P) print html('Final values:\n'),b.n() 
       

Click to the left again to hide and once more to show the dynamic interactive window

%auto show(A) show(b0)