running, the simplest way, for small examples, is just to define a variable A and then type in the values separating each row with a comma. Because this is.
E-APPENDIX NUMERICAL RECIPIES TO CALCULATE THE DOMINANT EIGENVALUE
This electronic-appendix provides programming scripts for finding the dominant or maximum eigenvalue of an n×n matrix and some other software tips for starting to use matrix projection models. Scripts are available for several commonly used programming languages.
Maple script Calculating the maximum eigenvalue of a nxn matrix Maple > restart; > with(LinearAlgebra): R defines the matrix structure: - Rows are defined within '[]' and separated by ','. - Matrix elements within a row are also separated by ','. > R := Matrix([ [a, b, c], [d, e, f], [g, h, i] ]); Lambdas calculates all the eigenvalues of matrix R. LambdasNonComplex removes the complex eigenvalues from the list, as Maple does not allow selection of maximum value from list containing complex numbers. MaxLambda converts vector Lamdas to a set of eigenvalues and then picks out the maximum eigenvalue. > Lambdas := evalf(Eigenvalues(R)); > LambdasNonComplex := remove(has, Lambdas, I): > MaxLambda := max(op(convert(LambdasNonComplex,set)));
1
A MaxLambda of -infinity suggests that all eigenvalues of the matrix are complex. Check the vector containing all eigenvalues (i.e., Lambdas).
Genstat script "Declare projection matrix, A, and specify its values. Note the matrix is written with line breaks so that it appears on screen in a readable format – there is no real need to do this and white space will be ignored when GenStat compiles the program. Print it out to check the values are in the right places." scalar [2] pops matrix [rows=pops; col=pops] A; \ values=!(1.1, 0.05,\ 0.05, 1.075) print A
"Extract eigenvalues and eigenvectors from matrix A. the 'latent roots and vectors' nomenclature.
Note that GenStat uses
The relevant values are obtained
using the FLRV (Form Latent Roots and Vectors) directive. produced by FLRV is a compound data structure. are stored in the second component of LRV.
The structure LRV
The eigenvalues (=latent roots)
This is indexed and equated to a
pre-declared variate to extract the values of interest for printing and further use.
Finally the value of R0 is obtained as the largest value from the variate
holding the eigenvalues."
variate [nval=pops] lambda_A flrv [print=*] A; LRV=LRV_A equate LRV_A[2]; lambda_A scalar R0 calc R0 = max(lamda_A) print lambda_A print R0
2
SAS script * Start by calling the interactive matrix language (IML) using proc iml; proc iml;
* The projection matrix can be entered in a number of ways.
Once IML is
running, the simplest way, for small examples, is just to define a variable A and then type in the values separating each row with a comma.
Because this is
being done inside IML, A is automatically defined as a matrix;
A={1.1 0.05, 0.05 1.075};
* call the eigenvalue function naming the structures to hold the eigenvalues, eigenvectors and which matrix to work on;
call eigen (eigenvals, eigenvecs, A);
*print the calculated values in a readable format, assign the value of the largest eigenvalue to R0 and print; print "The eigenvalues and eigenvectors of A are", "
" eigenvals [format=8.4] "
" eigenvecs [format=9.4];
R0 = max(eigenvals); print R0 [format=8.4];
Powerplay Powerplay is a useful free, software tool to help with model building. It was developed by the Loop Group at Oregon State University and is available from the group’s web site: http://www.ent.orst.edu/loop/aboutus.aspx .
3
The most common mistake in forming a projection matrix comes in translating the diagram of states and transitions (connections) into the matrix. Powerplay removes some of the error from this process by generating the projection matrix automatically from a diagram of the system being modelled. If no values for the transition rates and probabilities are specified Powerplay generates a binary matrix showing which connections exist and leaving the user to specify numerical values. A further useful feature for Maple users is that Powerplay produces Maple code which can be used as the input to the script given above. The use of Powerplay is illustrated here by using the 5×5 field example (Example 2) given in the paper.
Figure A.1 shows a Powerplay diagram of the connections in the 5×5 field example; the selfloops indicate auto-infection within each field. Figure A.2 shows the Matrix View window corresponding to Figure A.1. Note that in addition to showing the connections between components in the system, the window also shows how to specify the matrix in Maple statements (in the bottom line of text in the window).
Fig. A.1. Powerplay representation of the hypothetical system of 5 fields of susceptible host plants with connections between the fields indicating possible pathways of pathogen dispersal. Self-loops, representing pathogen multiplication within fields are shown. 4
Fig. A.2. The Matrix View window in Powerplay showing the binary connection matrix for the 5 field system and, highlighted, the automatically generated Maple statements to generate the matrix.
5