Khizran 2
Khizran 2
Khizran 2
AIM:
To generate matrix and perform basic operation on matrices Using MATLAB Software.
EQUIPMENTS:
PC
MATLAB Software
INTRODUCTION:
Matrices are the basic elements of the MATLAB environment. A matrix is a two-dimensional array consisting
of m rows and n columns. Special cases are column vectors (n = 1) and row vectors (m = 1).
MATLAB supports two types of operations, known as matrix operations and array
operations.
MATRIX GENERATION:
ENTERING A VECTOR
A vector is a special case of a matrix. The purpose of this section is to show how to
create vectors and matrices in MATLAB. As discussed earlier, an array × of
dimension 1 n is called a row vector, whereas × an array of dimension m 1 is
called a column vector. The elements of vectors in MATLAB are enclosed by square
brackets and are separated by spaces or by commas. For example, to enter a row
vector, v, type
>> v = [1 4 7 10 13]
v=
1 4 7 10 13
Column vectors are created in a similar way, however, semicolon (;) must separate
the components of a column vector,
>> w = [1;4;7;10;13]
w =
1
4
7
10
13
CONCATENATING MATRICES:
Matrices can be made up of sub-matrices. Here is an example. First, let’s recall our
previous matrix A.
A =
1 2 3
4 5 6
7 8 9
B=
1 2 3 10 20 30
4 5 6 40 50 60
7 8 9 70 80 90
-1 -2 -3 1 0 0
-4 -5 -6 0 1 0
-7 -8 -9 0 0 1
Matrix functions
det Determinant
diag Diagonal matrices and diagonals of a matrix
eig Eigenvalues and eigenvectors
inv Matrix inverse
norm Matrix and vector norms
rank Number of linearly independent rows or columns
Table 3.3: Matrix functions
LAB TASK
Generate a 4×4 Matrix A in MATLAB and multiply it with your registration number.
Delete the last row and last column of matrix A and take the square of the resulting matrix.
Replace the 3rd column of matrix A with all zeros.
Take transpose of that matrix
Q1: Generate a 4×4 Matrix A in MATLAB and multiply it with your registration number.
Matlab Simulation:
A = [5 8 6 9; 3 7 4 8; 4 2 1 9; 7 9 3 5 ]
B = A*6
Q2: Delete the last row and last column of matrix A and take the square of the resulting matrix.
Matlab Simulation:
A = [5 8 6 9; 3 7 4 8; 4 2 1 9; 7 9 3 5 ]
B = A(1:3,1:3)
= B^2