Lab No. 02: Objective
Lab No. 02: Objective
Lab No. 02: Objective
02
Objective: To learn about vectors, mathematical operation on vectors, matrices, mathematical operation
on matrices, solution set of matrices in Matlab.
Vector:
Vector is a sequence of regular or irregular numbers.
A=
1 2 3 4 5
A=
A=
1 2 3 4 5 6 7 8 9 10
B=
1 5 9 13 17
ans =
13
2 3 4 5
>> B=[3 5 6 7]
B=
3 5 6 7
>> A+B
ans =
5 8 10 12
Subtraction of vectors
>> A-B
ans =
-1 -2 -2 -2
Multiplication of vectors
For multiplication it is necessary that the number of rows of first vector must be equal to number of
columns of second vector
>> A*B'
ans =
80
Division of vectors
>> A/B
ans =
0.6723
ans =
Matrices in Matlab
Matrix is combination of rows and column vectors.
A=
1 2 3
4 5 6
7 8 9
ans =
ans =
7 8 9
ans =
8
Mathematical operation on Matrices
Addition of Matrices
For addition both the two matrices must be of same dimension.
A=
2 3 4
5 6 7
2 3 4
B=
1 2 3
4 5 6
7 8 9
>> A+B
ans =
3 5 7
9 11 13
9 11 13
Subtraction of Matrices
>> A-B
ans =
-2 -2 -2
3 1 1
0 0 0
Multiplication of Matrices
For multiplication of matrices the number of rows of first matrix must be equal to number of columns of
second matrix.
>> A*B
ans =
26 36 42
59 84 99
92 132 156
Division of Matrices
>> A/B
ans =
0 0 1.0000
Transpose of a Matrix
>> A'
ans =
1 4 7
2 5 8
3 6 9
Determinant of a Matrix
>> det(B)
ans =
-8
ans =
ans =
-0.0625 0.0625 -0.0000
ans =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
ans =
1 1 1
1 1 1
1 1 1
ans =
0 0 0
0 0 0
0 0 0
Lab. Assignment
Perform the following Mathematical operation in Matlab on the given Matrix.
Z=
3 4 7
11 15 19
2 4 6
1) Natural Log Operation
2) Square root
3) General log
4) Power operation.