Khizran 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

LAB NO: 02 BASIC OPERATIONS ON MATRICES

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).

In this section we will illustrate how to apply different operations on matrices.

MATLAB supports two types of operations, known as matrix operations and array
operations.

MATRIX GENERATION:

Matrices are fundamental to MATLAB. Therefore, we need to become familiar with


matrix generation and manipulation. Matrices can be generated in several ways.

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

The new matrix B will be,

>> B = [A 10*A; -A [1 0 0; 0 1 0; 0 0 1]]

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

MATLAB provides many matrix functions for various matrix/vector manipulations;


see Table 3.3 for some of these functions. Use the online help of MATLAB to find
how to use these 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

Concatenate the resulting matrix with an identity 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

You might also like