Lab-1: Study On Basic Matrix Operations Using Matlab
Lab-1: Study On Basic Matrix Operations Using Matlab
University of Dhaka
Department of Electrical and Electronic Engineering
EEE-3102: Numerical Technique Laboratory
Group :A
Class Roll : FH-073-018
Name : Md. Rafatul Haq
Date : 24/01/2022
Instruction: Use the concept on matrix operations in Matlab tutorial for this Lab.
Representation of Matrix in Matlab:
Consider two matrices M and N given below
1 2 −2 3 −1 2
M 3 −1 5 =
= N 5 1 −2
2 3 1 −1 4 1
In Matlab, we can represent matrix A in an m-file using the following command
M=[1 2 -2;3 -1 5;2 3 1];
Similarly, we can represent matrix B as given below
N=[3 -1 2;5 1 -2;-1 4 1]
Observation-1: Apply all the above operations listed in Table-1 for matrices M and N. For the
operation on a single matrix, use matrix M. Just observe the results. You don’t need to show the
results in your lab report.
Observation-3: Implement all of the typical matrices of size 5×5. Just observe the results. You don’t
need to show the results in your lab report.
Exercise
E1: Implement the following two matrices A and B in Matlab
2 3 5 −1 3 1 2 −1
−5 2 −1 2 −4 −5 5 2
A= B=
1 −4 7 6 1 −2 −3 3
5 2 1 −4 6 3 1 −4
(a) Find the 3rd row named r3 of M1 where M1 is obtained by adding A and B. Put r3 below.
r3 = [2 -6 4 9]
(b) Find the 4th column named c5 of M2 where M2 is obtained by element-by-element
multiplication between A and B. Put c5 below.
1
c5 = 4
18
16
(c) Find the 4th element in the 2nd column named e42 of M3 where M3 is obtained by matrix
multiplication between A and B. Put e42 below.
e42 = -2
(d) Determine the inverse of matrix A and put it below
-0.5208 0.5417 0.3229 0.8854
-0.3542 0.7083 0.2396 0.8021
0.4792 -0.4583 -0.1771 -0.6146
-0.7083 0.9167 0.4792 1.1042
(e) Determine the transpose of matrix B and put it below
3 -4 1 6
1 -5 -2 3
2 5 -3 1
-1 2 3 -4
3
-5
-3
-4
E2: Generate a 5×5 one-matrix named N1, a magic matrix N2, and a diagonal matrix N3. Find a matrix
E after dividing N1 by N2, Use element-by element division for this purpose. Now, find a matrix F
after performing matrix multiplication between N2 and N3. Now find a matrix G by adding matrices E
and F. You don’t need to put these results in your report. Now find
(a) the determinant d of matrix G and put the result below
d = 4.7375e+06
(b) Find the 2nd element in the 4th row r24 of G and put the result below
r24 = 12.0833
E3: (a) write matlab code to generate a 3×3 random matrix and RUN it. RUN the code again. Are the
results obtained from these two run same? Justify your answer
The results obtained from these two runs were not the same.
1st RUN:
-0.3034 0.8884 -0.8095
0.2939 -1.1471 -2.9443
-0.7873 -1.0689 1.4384
2nd RUN:
0.3252 -1.7115 0.3192
-0.7549 -0.1022 0.3129
1.3703 -0.2414 -0.8649