213 - A19 - Linear Dynamical System

7 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 pretty_print(html("<font size=+2 color=blue>Enter N below. Click Update when you are finished.</font>")) @interact def _(Size_of_System=[2..10],update=false): global N N = Size_of_System pretty_print(html("<font size=+2 color=blue>The size of your square system will be "+str(N)+"$\\times$"+str(N)+"</font>")) pretty_print(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. None
Size_of_System 
update 

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

%auto print pretty_print(html("<font size=+2 color=blue>Enter the transition matrix for your dynamical system and the starting state below.<p> 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 
       
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.

None

Transition_Matrix 
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_5.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/tmplYK6pT/___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.
       
[93/100   1/20]
[ 7/100  19/20]
[93/100   1/20]
[ 7/100  19/20]
%auto @interact def _(steps = slider(1,100,1,1)): global A,b b = copy(b0) print b terms = range(b.nrows()) colors = rainbow(b.nrows()) P = Graphics() # S = Graphics() for term in terms: P += point2d((0,b[term][0]),color=colors[term]) for k in range(1,steps): b = A*b # S += point2d((b[0][k],b[1][k])) for term in terms: P += point2d((k,b[term][0]),color=colors[term],size=30) show(P) # show(S) print pretty_print(html('Final values:\n'),b.n()) 
       
steps 

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

%auto show(A) show(b0) show(b) 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'A' is not defined
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_7.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("c2hvdyhBKQpzaG93KGIwKQpzaG93KGIp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpKOCB0S/___code___.py", line 2, in <module>
    show(A)
NameError: name 'A' is not defined
(-5/92*3/95+100/95) 
       
1837/1748
1837/1748
A = matrix([[95/100,3/100],[5/100,97/100]]) C = A.inverse() x = matrix([[582],[418]]) x0 = C*x x1 = A*x0 x2 = A*x1 x3 = A*x2 print(x3) C^3*x3 
       
[343878/625]
[281122/625]
[600]
[400]
[343878/625]
[281122/625]
[600]
[400]