使用Matlab完成矩阵相关的计算

Tutorial 5

PART ONE: paper and pen

1. Reduce the following matrix to its row echelon form and to a reduced row echelon form

0 1 2

1 2 1

2 7 8

2. What is the rank of the matrix, check your answer in matlab

3. Calculate the eigenvalues and eigenvectors of the below matrix.

»

»

»

¼

º

«

«

«

¬

ª

0 0 2

0 2 0

2 1 0

A

PART TWO: Use matlab to solve the following exercises

1. Create a 1 x 5 vector a with all elements equal to 0

2. Create a 3 x 1 vector b with all elements equal to 1

3. Create a 1 x 5 vector c with elements equal to 1, 2, 3, 4, π respectively.

4. Create 1-row vector d with elements from 3 to 27 with step 3 by using the appropriate

operator.

5. Create a 3 x 3 matrix E with elements with random values.

6. Create the following matrix

7. Check the size of F

8. Create the following Matrix

a. find the transpose of G

b. print on display the element G13 of the transpose of G

c. print on display the second row of the transpose of G

d. print on display the third column of the transpose of G

e. find the determinant of G (Verify that this is correct using a pen a paper)

f. Compute the inverse of G and print on display the element in the second row and

second column.

9. Create the following Matrices

a. Find the Matrix H+J

b. Find the Matrix H * J

c. Multiply H by J, element-by-element

10. Solve the linear system of equations Ax=b if

11. Create a 1 x 5 vector with elements with random values

12. Use the “for” loop to find the greatest element of the matrix

13. Use the “while” loop to find the smallest element of the matrix

PART THREE: Limited / no support from TAs for this exercise

The solution of this Problem has to be submitted online.

ONLY the below exercise has to be submitted. Submit your code online and remember your

name and k-number. Your code will only be marked if it can run without issue displaying the

covariance matrix

The table below displays scores on math, English, and art tests for 5 students.

Student Math English Art

1 90 60 90

2 90 90 30

3 60 60 60

4 60 60 90

5 30 30 30

Note that data from the table can be represented in matrix A, where each column in the matrix shows

scores on a test and each row shows scores for a student.

b

A =

90 60 90

90 90 30

60 60 60

60 60 90

30 30 30

Given the data represented in matrix A, compute the variance of each test and the covariance between

the tests. Print on display the elements of the covariance matrix.

Variance-Covariance Matrix

Variance and covariance are often displayed together in a variance-covariance matrix, (aka, a

covariance matrix). The variances appear along the diagonal and covariances appear in the offdiagonal elements, as shown below. Covariance is a measure of the joint variability of two random

variables.

V =

Σ x1

2 / N Σ x1 x2 / N . . . Σ x1 xc / N

Σ x2 x1 / N Σ x2

2 / N . . . Σ x2 xc / N

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

Σ xc x1 / N Σ xc x2 / N . . . Σ xc

2 / N

where

V is a c x c variance-covariance matrix

N is the number of scores in each of the c data sets

xi is a deviation score from the ith data set

Σ xi

2 / N is the variance of elements from the ith data set

Σ xi xj / N is the covariance for elements from the ith and jth data sets

Solution guide

The solution involves a three-step process.

1. First, transform the raw scores in matrix A to deviation scores in matrix a, using the

transformation formula: a = A – (1*1′)*A ( 1 / n )

where

1 is an n x 1 column vector of ones.

a is a matrix of deviation scores

A is a matrix of raw scores:

n is the number of rows in matrix A

2. Then, to find the deviation score sums of squares matrix, we compute

3. And finally, to create the variance-covariance matrix, we divide each element in the deviation

sum of squares matrix by n, as shown below.

## 发表评论