Documente Academic
Documente Profesional
Documente Cultură
LABORATORY ACTIVITY #2
MATRICES
Name: Date:
Section: Laboratory Instructor:
I. Learning Outcomes:
At the end of the laboratory activity, the students should be able to:
1. Use MATLAB in creating and manipulating matrices.
2. Solve linear systems of equation using MATLAB
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 0
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1C. a. Problem: 4 by 5 zeros
b. MATLAB Codes: >> A= zeros(4,5)
c. Answer:
A=
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
1D. a. Problem: 4 by 4 uniformly distributed pseudorandom numbers
b. MATLAB Codes: >> A= rand(4,4)
c. Answer:
A=
2. a. Problem: If A = magic (24), what is the value in row 21, column 22?
b. MATLAB Codes: >> A= magic(24)
A=
Columns 1 through 12
Columns 13 through 24
3 0 0 0 0
0 6 0 0 0
0 0 9 0 0
0 0 0 12 0
1 0 0 0 15
4. a. Problem: Using magic square of 5, write the values in lower triangular.
b. MATLAB Codes: >> M= magic(5)
M=
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
c. Answer: M=
17
23 5
4 6 13
10 12 19 21
11 18 25 2 9
M=
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
c. Answer: M=
16 2 3 13
11 10 8
6 12
1
6. a. Problem: Determine the determinant of the matrix.
[ ]
1 3 6
2 5 9
7 2 23
b. MATLAB Codes: >> A= [1,3,6;-2,5,9;7,-2,23]
A=
1 3 6
-2 5 9
7 -2 23
>> C= det(A)
c. Answer: C = 274
A=
1 -12 13 -7
2 15 16 12
4 -10 1 17
3 2 -3 2
>> C=det(A)
c. Answer: C = 28495
1 2 3 4
6 8 1 5
9 4 2 7
9 4 7 2
B=
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
C=
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
D=
1 0 0 0
0 3 0 0
0 0 5 0
0 0 0 7
E=
1 0 0 0
0 1 0 0
0 0 0 1
1 0 0 0
F=
3 6 9 12
18 24 3 15
27 12 6 21
27 12 21 6
9. a. Problem: Using the matrices of #8, solve the following:
9A. 3A+4F
9B. ABC/4F
9C. 2DEF+4B
9D. FEB/2CD
9E. (2B 3D)(2ABC)
b. MATLAB Codes: >> 3*A+4*F
>> (A*B*C)/(4*F)
>> ((2*D)*E*F)+(4*B)
>> (F*E*B)/(2*C*D)
>> ((2*B)-(3*D))*(2*A*B*C)
c. Answer: 9A =
15 30 45 60
90 120 15 75
135 60 30 105
135 60 105 30
9B =
10 16 22 28
112 148 22 94
274 124 214 64
46 88 130 172
9D =
1.0e+016 *
Columns 1 through 3
Column 4
8024
-2176
-12376
-21352
10. a. Problem: Create the matrix below using the matrices of #8.
1 2 3 4 2 2 2 2 4 3 3 3
6 8 1 5 2 2 2 2 3 4 3 3
9 4 2 7 2 2 2 2 3 3 3 4
9 4 7 2 2 2 2 2 4 3 3 3
1 4 7 10 16 2 3 13 1 0 0 0
16 22 1 13 5 11 10 8 0 3 0 0
25 10 4 19 9 7 6 12 0 0 5 0
25 10 19 4 4 14 15 1 0 0 0 7
c. Answer: ans =
1 2 3 4 2 2 2 2 4 3 3 3
6 8 1 5 2 2 2 2 3 4 3 3
9 4 2 7 2 2 2 2 3 3 3 4
9 4 7 2 2 2 2 2 4 3 3 3
1 4 7 10 16 2 3 13 1 0 0 0
16 22 1 13 5 11 10 8 0 3 0 0
25 10 4 19 9 7 6 12 0 0 5 0
25 10 19 4 4 14 15 1 0 0 0 7