0% found this document useful (0 votes)
16 views

MATLAB EXPERIMENT 3

Uploaded by

Aadil Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

MATLAB EXPERIMENT 3

Uploaded by

Aadil Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT-III

3.1 Objectives

Generate a matrix and perform basic operation on matrices using MATLAB software.

3.2 Software Required: MATLAB software

3.3 Theory: software.

MATLAB treats all variables as matrices. Vectors are special forms of matrices and contain

only one row or one column. Whereas scalars are special forms of matrices and contain only

one row and one column. A matrix with one row is called row vector and a matrix with single

column is called column vector.

The first one consists of convenient matrix building functions, some of which are given
below:

1. eye - identity matrix


2. zeros - matrix of zeros
3. ones - matrix of ones
4. diag - extract diagonal of a matrix or create diagonal matrices
5. triu - upper triangular part of a matrix
6. tril - lower triangular part of a matrix
7. rand - ran
commands in the second sub-category of matrix functions are
1. size- size of a matrix
2. det -determinant of a square matrix
3. inv- inverse of a matrix
4. rank- rank of a matrix
5. rref- reduced row echelon form
6. eig- eigenvalues and eigenvectors
7. poly- characteristic polynomialdomly generated matrix

3.4 Programs:

❖ Creating a column vector


>> a=[1;2;3]
a=
1
2
3
❖ Creating a row vector
>> b=[1 2 3]
b=
123
❖ Creating a matrix
>> m=[1 2 3;4 6 9;2 6 9]
m=
123
469
269

❖ Extracting sub matrix from matrix

>> sub_m=m(2:3,2:3)
sub_m =
69
69

❖ extracting column vector from matrix


>> c=m (:,2)
c=
2
6
6

❖ extracting row vector from matrix


>> d=m (3,:)
d=
269

❖ creation of two matrices a and b


>> a=[2 4 -1;-2 1 9;-1 -1 0]
a=
2 4 -1
-2 1 9
-1 -1 0
>>b=[0 2 3;1 0 2;1 4 6]
b=
023
102
146

❖ matrix multiplication
>> x1=a*b
x1 =
308
10 32 50
-1 -2 -5

❖ element to element multiplication


>> x2=a.*b
x2 =
0 8 -3
-2 0 18
-1 -4 0

❖ matrix addition
>> x3=a+b
x3 =
262
-1 1 11
036

❖ matrix subtraction
>> x4=a-b
x4 =
2 2 -4
-3 1 7
-2 -5 -6

❖ matrix division
>> x5=a/b
x5 =
-9.0000 -3.5000 5.5000
12.0000 3.7500 -5.7500
3.0000 0.7500 -1.7500

❖ element to element division


>> x6=a./b
Warning: Divide by zero
x6 =
Inf 2.0000 -0.3333
-2.0000 Inf 4.5000
-1.0000 -0.2500 0

❖ inverse of matrix a
>> x7=inv(a)
x7 =
-0.4286 -0.0476 -1.7619
0.4286 0.0476 0.7619
-0.1429 0.0952 -0.4762

❖ transpose of matrix a
>> x8=a'
x8 =
2 -2 -1
4 1 -1
-1 9 0

3.5 Result: Matrix operations are performed using Matlab software.

You might also like