Part A: Working With Matrices
Part A: Working With Matrices
Part A: Working With Matrices
Department of Mathematics
MA1506 Laboratory 3 (MATLAB)
Part A: Working With Matrices
MATLAB actually stands for matrix laboratory, and as the name suggests, it was designed
for working with matrices.
We can input an m n matrix A by
A = [ row 1; row 2; ... ; row m ]
where the n entries of each row are separated by one or more blank spaces. For example:
>> A=[3 2 -1 ; 0 1 0 ; 1 2 2]
The following commands perform basic operations on matrices A and B:
A+B matrix addition
A-B matrix subtraction
tA scalar multiplication, with t scalar
AB matrix multiplication
A
1 0 0
0 0 1
0 1 0
0 1 0
1 0 0
0 0 1
0 1 0
1 0 0
0 0 1
1 0 0
0 0 1
0 1 0
.
1
>> A=[ 1 0 0 ; 0 0 -1 ; 0 1 0]
>> B=[ 0 -1 0 ; 1 0 0 ; 0 0 1]
>> A*B
>> B*A
3. Compute the transpose of the matrix M =
1 2 4
6 8 9
and N =
1 2 4
6 8 9
2 1 0
.
Verify that N
T
+ N is symmetric and N
T
N is anti-symmetric.
>> M=[ 1 2 4 ; 6 8 9]
>> M
>> N=[ 1 2 4 ; 6 8 9 ; 2 1 0]
>> N + N
>> N - N
4. Using M and N dened previously, predict what happens if we try to perform the
matrix addition M + N and the matrix multiplications MN and NM. Verify your
prediction.
>> M + N
>> M*N
>> N*M
5. Determine if the following matrices, C1 =
2 7 5
1 3 1
4 13 3
and C2 =
2 7 5
1 3 1
4 13 4
are invertible.
>> C1=[ 2 7 5 ; 1 3 -1 ; 4 13 3]
>> C2=[ 2 7 5 ; 1 3 -1 ; 4 13 4]
>> det(C1)
>> det(C2)
>> inv(C2)
>> inv(C2)*C2
6. Let D =
5 7 9
8 8 1
20 4 6
and E =
1 2 4
1 1 1
1 1 0
b is a column vector.
>> A= [1 -1 1; 1 1 0; 1 2 -1]
>> b= [ 4; 1; 0]
>> det(A)
3
Since det(A) = 0, the matrix is non-singular. We can then solve the system by
nding the inverse of A. The required solution is x = A
1
b.
>> x= inv(A)*b
10. In 1966, Leontief used his input-output model to analyze the Israeli economy by
dividing it into three segments: Agriculture (A), Manufacturing (M), and Energy
(E), as shown in the following technology matrix.
Output \ Input A M E
A $0.30 $0.00 $0.00
M $0.10 $0.20 $0.20
E $0.05 $0.01 $0.02
The export demands on the Israeli economy are listed as follows: Agriculture: $140
million, Manufacturing: $20 million and Energy: $2 million.
To nd the total output for each sector required to meet both internal and external
demand, we must solve the following system
A = 0.30A + 0.00M + 0.00E + 140
M = 0.10A + 0.20M + 0.20E + 20
E = 0.05A + 0.01M + 0.02E + 2.
Using the technology matrix T, we have x = (I
3
T)
1
b.
>> T=[ .3 0 0 ; .1 .2 .2 ; .05 .01 .02]
>> b=[140; 20; 2]
>> x= inv(eye(3)- T)*b
The required output is approximately, A = $200 m , M = $53 m and E = $13 m.
Note that eye(3) is the MATLAB command for the 3 3 identity matrix.
4
Part B: Eigenvectors And Eigenvalues
We know that the matrix
1 2
2 2
has an eigenvector
2
1
2
1
but a multiple of it. Remember that eigenvectors are never unique, and the eig function
will compute eigenvectors with lengths 1. To get our familiar
2
1
1 1 13 6.5 1.5
1 1 0 0 0
1 2 1 3 1
1 7 1 4 9
1.5 2 21 3 1
.
(i) 615.75
(ii) -516.5
(iii) 765.0
(iv) 716.25
2. A car rental agency has three branches A, B and C. The company policy allows cars
to be rented from and returned to any one of the three branches. A statistical study
revealed that the chances of cars being returned to the same branch where they were
rented are 70%, 50% and 40% respectively. There is a 20% likelihood of cars rented
from branch A being returned to branch B. A 30% chance of cars rented from branch
B being returned to branch C and also a 30% chance of cars rented from branch C
being returned to branch A. Assuming the company started with 100 cars at each
branch, in the long run, approximately how many cars will remain at branch C?
(i) 23
(ii) 70
(iii) 134
(iv) 32
3. A small countrys economy is divided into three segments: Electronics (E), Manufac-
turing (M), and Pharmaceutical (P), as shown in the following technology matrix.
Output \ Input E M P
E $0.15 $0.20 $0.00
M $0.10 $0.30 $0.00
P $0.12 $0.18 $0.40
6
The export demands are as follows: Electronics: $80 million, Manufacturing: $20
million and Pharmaceutical: $10 million.
The electronics output is approximately (nearest million)
(i) $ 104 million
(ii) $ 100 million
(iii) $ 89 million
(iv) $ 80 million
4. Find the eigenvalues and a matrix P that diagonalizes
5 6 2
0 1 8
1 0 2
.
5. Find the eigenvalues and a matrix P that diagonalizes
2 1
5 2
.
6. Find the eigenvalues and a matrix P that diagonalizes
5 0 0
1 5 0
0 1 5
.
7. In order to nd the eigenvalues of a matrix A, we solve the characteristic equation
0 = det(A I) = c
n
n
+ c
n1
n1
+ + c
1
+ c
0
,
which is a polynomial equation in . The coecients of the characteristic polynomial
can be found with the command
>> poly(A)
There is a remarkable theorem called the Cayley-Hamilton Theorem which states
that a square matrix A satises its characteristic equation. Hence
c
n
A
n
+ c
n1
A
n1
+ + c
1
A + c
0
I
n
= 0.
Verify this for the three matrices given above.
The End
7