MATLAB Linear Algebra assignment (matrices/eigenvalues)

profilesenthra95
LesliematricesandIntroductiontoMATLAB.docx

Introduction to MATLAB and Leslie Matrices

1) Start MATLAB

2) You can type commands directly into the command window: Type and expression and then hit enter to evaluate the expression. For example you can add 2 and 2:

>> 2+,2

If you want to suppress the output of a command follow it with ‘;”. For example “2+2”;

3) Practice evaluating a few expressions in the command window. (In MATLAB multiplication is represented by * so 3*2=6).

4) You can also define variables in the command window. For example, to set the value of the variable x equal to 2 just type “x=2” and hit enter. Notice that the variable x now appears in your workspace on the far right hand side.

5) Variables can also be vectors or matrices. For example “x=[1 2 3]” creates a row vector with x(1)=1, x(2)=2, and x(3)=3. What happens when you type “x=[1;2;3]”?

6) Create a 3x3 matrix named A with rows [1 2 3], [4, 5, 6], and [7, 8, 9].

7) You can also create functions in the command window. We will create functions of two variables, x and y. (Later these functions will be the right hand side of a first order differential equation.) For example to create a function g(A,x)=A*x type “g=@(A,x) (A*x)” and press enter.

8) Now that you have created the function g(x,y) you can evaluate it at different x and y values. For example, to compute g(1,2), just enter: “g(1,2)”. Also compute g(A,x0), for x0=[1 1 1]T. Note that x0 must be passed to g as a column vector so that the dimensions of A and x0 are consistent for multiplication.

9) To can use a for loop to compute and store the values of Anx for several values of n. For example, type “y=zeros(3,4); for i=1:4 y(:,i)=A^i*x; end” to store the values of An for n=1, . . , 4 as the columns of the matrix y. That is the ith column of y is Aix0.

10) You can plot your answer by typing “plot([1 2 3 4], y, ‘o’)”.

11) To compute the eigenvalues and eigenvectors of a matrix A in MATLAB, type “[V, D]=eig(A)”.

The matrix V has the eigenvectors of A as its columns. The matrix D has the corresponding eigenvalues of A on its diagonal. Find the eigenvalues and eigenvectors of the matrix A that is stored in your workspace.

12) If x is a vector, the command “sum(x)” returns the sum of the elements in x. Normalize the eigenvectors of A so that each eigenvector sums to one.

13) Construct the Leslie matrix for the northern fur seal population in exercise 22 on page 359 of your text.

C:\Users\Brandon\Downloads\IMG_20171130_132845.jpg

14) Find the eigenvalues and eigenvectors of this Leslie matrix. Predict the long-term population growth rate and steady state population structure.

15) Suppose that a group of fur seals, including 50 females between the ages of 2 and 4 years are introduced to a large island off the coast of British Columbia. Find the total number of female seals predicted to be in the population 1-10 years later. Plot your answer. Edit your plot so that it is easy to read and includes a title and x- and y-axis labels.

16) Predict the percentage of seals aged 0-2 years in years 0-10 (even years only). Plot your answer. Edit your plot so that it is easy to read and includes a title and x- and y-axis labels.