University of Michigan



Math 216 - Assignment 3 - Linear Algebra

Due: Tuesday, March 27. Nothing accepted after Thursday, March 29. This is worth 15 points. 10% points off for being late. You may work by yourself or in pairs. If you work in pairs it is only necessary to turn in one set of answers for each pair. Put both your names on it.

Do Problems 1 - 12 in the discussion below. Copy and paste the input and output for each problem from the Command Window (or plot window) to a Microsoft Word file. Do this after you are satisfied with your input and output. Label the work for each problem in the Word file: Problem 1, Problem 2, etc. Print a copy of this file to hand in. Or use a Live Script.

Lab 1 looked at the representation of vectors. Here we look at the representation of matrices and calculations with vectors and matrices.

More about vectors

To represent a row vector, one encloses the components in brackets and separates them with spaces or commas. To represent a column vector one separates the components with semicolons instead of spaces or commas. For example, the following commands assign the row vector (2, - 1, 3) to p and the column vector to x. The number of components of a vector p is obtained by length(p).

>> p = [2, - 1, 3];

>> x = [4; - 6; - 3];

>> length(x)

ans =

3

If one uses spaces to separate the components of a vector, then the minus sign that specifies a negative number must not be separated from the rest of the number by a space. If it is, then the rest of the number is subtracted from the preceding component. For example,

>> [2 - 1 3]

ans =

1 3

>> [2 -1 3]

ans =

2 -1 3

The colon notation is used to create row vectors whose components are separated by a fixed amount. For example, this assigns the row vector (2, 2.5, 3, 3.5, 4) to q.

>> q = 2: 0.5: 4

A single quote ' is the transpose operator. When it is applied to vectors it changes a row vector to a column vector with the same components or a column vector to a row vector with the same components. For example, the following forms the transpose of the vector stored in p and assigns it to y.

>> y = p'

y =

2

- 1

3

Vectors can be concatenated (or joined together). If p and q are row vectors, then [p, q] or [p  q] is the row vector consisting of the components of p followed by the components of q. For example, if p = (2, -1, 3) and q = (2, 2.5, 3, 3.5, 4) are as above then [p, q] = (2, -1, 3, 2, 2.5, 3, 3.5, 4)

>> r = [p, q]

r =

2.0000 -1.0000 3.0000 2.0000 2.5000 3.0000 3.5000 4.0000

More than two vectors can be concatenated in this way. For example, [p  q  3:-1:1] = (2, -1, 3, 2, 2.5, 3, 3.5, 4, 3, 2, 1).

p(j) refers to the jth component of the vector p. This notation can be extended to create a vector of arbitrary components of another vector. If p = (p1, p2, ..., pn) is a vector and if k = (k1, k2, ..., km) is a vector of integers then p(k) is the vector (pk1, pk2, ..., pkm). For example,

>> q([4, 1, 3, 5, 2])

ans =

3.5000 2.0000 3.0000 4.0000 2.5000

>> q(4:-1:2)

ans =

3.5000 3.0000 2.5000

[ ] denotes the empty vector. One can delete a component of a vector by setting it equal to [ ]. For example,

>> q(3) = [ ]

q =

2.0000 2.5000 3.5000 4.0000

Problem 1: Scalar variables are also vectors! Define a scalar variable (e.g. x = pi). Find its length?

Problem 2: Assuming r = (r1, r2, ..., r8) is as above, compute (r7, r2, r5). Compute (r2, r3, ..., r7) using the colon notation. Compute (r8, r6, r4, r2) using the colon notation.

Problem 3: Suppose p = [3 1 4 1 5 9 2 6 5 3 5 2 7 1 8 2 8 1 8 2 8] is a vector. Compute the vector q whose components are the components of p in the reverse order without simply entering them in reverse order. Use the colon notation.

Problem 4: Create the vector p = [1, 2, ..., 10, 9, ..., 6, 5, 6, ..., 9, 10, 9, ..., 2, 1] using the colon notation and concatenation.

A number of vector operations were discussed in the first Lab. In particular the product of a row vector and a column vector is formed using *. For example, here is px = p1x1 + ... + pnxn.

>> p*x

ans =

5

Matrices

A matrix is a two dimensional table of numbers, e.g. M = is a matrix with 2 rows and 6 columns. To enter a matrix, we enter the rows one at a time as row vectors and we use a semicolon between each row and enclose the whole matrix in square brackets. For example, M above would be entered by

>> M = [1, 4, 1, 4, 2, 1; 2, 2, 3, 6, 0, 6]

M =

1 4 1 4 2 1

2 2 3 6 0 6

Commonly used matrices have shortcuts to create them. For example, zeros(2, 4) is a 2(4 matrix of all zeros, ones(3, 2) is a 3(2 matrix of all ones, eye(3) is the 3(3 identity matrix, diag([3, -2, 4]) is a 3(3 diagonal matrix with 3, -2 and 4 on the main diagonal and zeros off the main diagonal.

Problem 5: Enter the following matrices A = , B = , C = , D = , E = 

size(M) is the size of the matrix M which is a row vector with the number of rows of M and the number of columns of M.

>> size(M)

ans =

2 6

M(i, j) refers to the component in the ith row and jth column of M.

>> M(2, 4)

ans =

6

Problem 6: Change the component in the 2nd row and 3rd column of M to 40. Then add 1 to the component in the 1st row and the 2nd column of M.

As with vectors, one can refer to more than a single component. M(i, :) is the ith row of M. M(:, j) is the jth column of M. M(i:j, m:n) is the submatrix of M consisting of the components whose row is between i and j and whose column is between m and n. When the colon is used by itself, it means "select all". For example M(3:5,:) is the submatrix of M consisting of rows 3 through 5 of M. Determine which values of M you get when you enter each of the following commands.

>> M(2, :)

>> M(:, 4)

>> M(1, 2:4)

>> M(:, 3:5)

Problem 7: Compute the vector consisting of the elements of M that are in column 2. Compute the submatrix of M consisting of the elements in columns 2 through 5.

Enter the following sequence of commands which assign the matrix to A, add 4 times the first row of A to the second, divide the third row by 2 and then interchange the second and third rows. The commands are doing row operations on the matrix A that are working toward bringing it to reduced row echelon form.

>> A = [1 -2 1 0; -4 5 9 -9; 0 2 -8 8]

>> A(2,:) = A(2,:) + 4*A(1,:)

>> A(3,:) = A(3,:)/2

>> A(2:3, :) = A(3:-1:2,:)

Problem 8: After entering the above commands, enter some more commands to bring to reduced row echelon form. The commands will need to add or subtract multiples of one row to another, interchange rows and multiply rows by numbers. These operations simply imitate the things one does with the equations in a system of equations when one solves the equations using Gaussian elimination. In this case reduced row echelon form is when the matrix has the form where a, b and c are numbers you are to find. These numbers will be the solutions to the system of equations ?

In practice one would not solve a system of equations by doing individual row operations to bring the augmented matrix to reduced row echelon form. A faster way is to use the \ operator. To do this we put the coefficients of the unknowns in a matrix T, the right hand side of the equations in a column vector b. Then the vector of solutions is obtained by entering T\b. The solution is T-1b, but T\b is the best way to compute this in MATLAB.

>> T = [1 -2 1; -4 5 9; 0 2 -8]

>> b = [0; -9; 8]

>> T\b

ans =

29

16

3

Matrices can be concatenated in a fashion similar to vectors. If M and N are matrices with the same number of rows, then [M, N] or [M  N] is the matrix whose ith row consists of the ith row of M concatenated with the ith row of N. If M and N are matrices with the same number of columns, then [M; N] or [M  N] is the matrix whose jth column consists of the jth column of M concatenated with the jth column of N. For example

>> A = [1 2; 3 4];

>> B = [5 6; 7 8];

>> [A B]

ans =

1 2 5 6

3 4 7 8

>> [A; B]

ans =

1 2

3 4

5 6

7 8

Matrix Operations

The usual matrix operations work as expected. If M and N are matrices then transpose(M) or M' is the transpose of M, inv(M) is the inverse of M, M + N and M - N are the sum and difference of M and N and M * N is the matrix product of M and N. If t is a number then t*M is the usual product of the number t times the matrix M. If t is a positive integer then M^t is the matrix obtained by multiplying M by itself t times.

Problem 9: Suppose, as in Problem 5, A = , B = , C = , D = , E = . Compute (A + 2I)-1(C - 3E). Here I = is the 2(2 identity matrix.

As an illustration of matrix multiplication, let's recall some information about geometric transformations. In the following x = and y = are points in the plane. If one obtains y by reflecting x across the x1 axis then y = x. If one obtains y by reflecting x across then x2 axis then y = x. If one obtains y by reflecting x across the line x1 = x2 axis then y =  x. If one obtains y by reflecting x through the origin the x2 axis then y = x. If one obtains y by projecting onto the x across the x1 axis then y =  x. If one obtains y by rotating x counterclockwise by an angle ( about the origin the x2 axis then y = x. Suppose one obtains y from x by first doing a geometric transformation with formula z = Tx and then doing a geometric transformation with formula y = Sz. Then y = Rx where R = ST.

With this in mind, suppose one obtains y from x by first rotating counterclockwise by 60(, then reflecting across the line x2 = x1 and finally by rotating clockwise by 45(. Find T so that y = Tx. The following sequence of commands find T.

>> A = [cos(pi/3) -sin(pi/3),sin(pi/3) cos(pi/3)];

>> B = [0 1;1 0];

>> C = [cos(- pi/4) -sin(- pi/4),sin(- pi/4) cos(- pi/4)];

>> C*B*A

ans =

0.9659 -0.2588

-0.2588 -0.9659

As an illustration of raising a matrix to a positive integer power, suppose x and y are represent two physical quantities that evolve in discrete time so that xn and yn are the values of discrete time n. Suppose x and y evolve in time in such a way that or in matrix terms un+1 = Aun where un = and A = . Then = An.

With this in mind, suppose xn is the number of population of a city n years from the year 2017 and yn is the population of the suburbs. Suppose in the course of a year 5% of the city's population moves to the suburbs and 3% of the suburbs population moves back to the city. Suppose the population of the city in the year 2017 is 600,000 and the population of the suburbs is 400,000. What would this model predict the populations of the city and suburbs to be in the year 2025? The following sequence of commands can be used to answer this.

>> A = [0.95 0.03;0.05 0.97];

>> x17 = [600000; 400000];

>> A8 = A^8

>> A8 * x17

A8 =

0.6958 0.1825

0.3042 0.8175

ans =

1.0e+05 *

4.9047

5.0953

So according to this model the population of the city in 2025 would be about 490,470 and the population of the suburbs would be about 509,530. Note the output writes the answer as 105 . Also, after 8 years about 30.5% of the people in the city have ended up in the suburbs and about 18% of the people in the suburbs are back in the city.

If M is a square matrix, then det(M) is the determinant of M.

If M is a square matrix, then [V, D] = eig(M) gives a diagonal matrix D with the eigenvalues of M and a matrix V of corresponding eigenvectors. Thus M*V = V*D. For example,

>> A = [1, 3; 4, 2];

>> [T, D] = eig(A)

T =

-0.7071 -0.6000

0.7071 -0.8000

D =

-2 0

0 5

So the eigenvalues are (1 = 2 and (2 = 5. The eigenvectors for the eigenvalue (1 = 2 are the multiples of u1 = . It would be equally valid to say the eigenvectors for the eigenvalue (1 = 2 are the multiples of v1 = . The eigenvectors for the eigenvalue (2 = 5 are the multiples of u2 = . It would be equally valid to say the eigenvectors for the eigenvalue (2 = 2 are the multiples of v2 = .

If M and N are matrices which have trfhe same size then M .* N, then this is the matrix obtained by multiplying the corresponding components of M and N. This is similar to vectors.

If you double-click on a vector or matrix variable such as M in the Workspace a new window opens up with a spreadsheet like table with the components of the vector or matrix stored in the variable. This table is editable. In fact, you can change the dimension of v by entering values in empty cells, or by control-clicking on a cell and deleting a row or column.

Problem 10: Use the \ operator to find the solution of .

Problem 11. Suppose one obtains y from x by first projecting on the x2 axis, then rotating counterclockwise by 45(, and finally reflecting across the x1 axis. Find T so that y = Tx.

Problem 12. Find the eigenvalues and eigenvectors of .

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download