0% found this document useful (0 votes)
9 views9 pages

MATLAB Matrix Operations Assignment

Uploaded by

Jeyanthan S
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)
9 views9 pages

MATLAB Matrix Operations Assignment

Uploaded by

Jeyanthan S
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

MATLAB

LAB ASSIGNMENT-1

NAME : ADITYA DAS


REGISTER NO. : 25BEE1081
QUESTION 1:
Find the transpose, inverse, determinant, eigenvalues, rank, lower triangular matrix,
upper triangular matrix, and perform matrix addition, subtraction, and multiplication
with itself for the following matrices. Also write a MATLAB code for matrix with all
zeros for 4 X 4, identity matrix of order 4 X 4.
2 1 1
[1 1 1]
1 -1 2

MATLAB CODE:

clc
clear all

a = [2 1 1;
1 1 1;
1 -1 2];

fprintf("Given Matrix: %s \n \n", mat2str(a));

fprintf("Transpose Matrix: %s \n \n", mat2str(transpose(a)));

fprintf("Inverse Matrix: %s \n \n", mat2str(inv(a)));

fprintf("Determminant of Matrix: %d \n \n", det(a));

fprintf("Eigenvalue Matrix: %s \n \n", mat2str(eig(a)));

fprintf("Rank of Matrix: %s \n \n", mat2str(rank(a)));

fprintf("Upper triangluar Matrix: %s \n \n", mat2str(triu(a)));

fprintf("Lower triangular Matrix: %s \n \n", mat2str(tril(a)));

fprintf("Addition with itself: %s \n \n", mat2str(a+a));

fprintf("Subtraction with itself: %s \n \n", mat2str(a-a));

fprintf("Multiplication with itself: %s \n \n", mat2str(a*a));

fprintf("4 X 4 Matrix with only zeros: %s \n \n", mat2str(zeros(4)));

fprintf("4 X 4 Identity Matrix: %s \n \n", mat2str(eye(4)));


OUTPUT:
QUESTION 2:

Find the transpose, inverse, determinant, eigenvalues, rank, lower triangular matrix,
upper triangular matrix, and perform matrix addition, subtraction, and multiplication
with itself for the following matrices. Also, write a MATLAB code to eliminate the
third column of the matrix and interchange the first row with the third row.
3 0 2
[2 0 −2]
0 1 1
MATLAB CODE:

clc
clear all

a = [3 0 2;
2 0 -2;
0 1 1];

fprintf("Given Matrix: %s \n \n", mat2str(a));

fprintf("Transpose Matrix: %s \n \n", mat2str(transpose(a)));

fprintf("Inverse Matrix: %s \n \n", mat2str(inv(a)));

fprintf("Determminant of Matrix: %d \n \n", det(a));

fprintf("Eigenvalue Matrix: %s \n \n", mat2str(eig(a)));

fprintf("Rank of Matrix: %s \n \n", mat2str(rank(a)));

fprintf("Upper triangluar Matrix: %s \n \n", mat2str(triu(a)));

fprintf("Lower triangular Matrix: %s \n \n", mat2str(tril(a)));

fprintf("Addition with itself: %s \n \n", mat2str(a+a));

fprintf("Subtraction with itself: %s \n \n", mat2str(a-a));

fprintf("Multiplication with itself: %s \n \n", mat2str(a*a));

%Eliminating third column


a(:,3) = [];

fprintf("Matrix after eliminating 3rd column : %s \n\n", mat2str(a));

%Interchanging 1st row with 3rd row


row1 = a(1,:);
a(1,:) = a(3,:);
a(3,:) = row1;
fprintf("Matrix after interchanging 1st row with 3rd row : %s \n\n", mat2str(a));
OUTPUT:
QUESTION 3:

Find the transpose, inverse, determinant, eigenvalues, rank, lower triangular matrix,
upper triangular matrix, and perform matrix addition, subtraction, and multiplication
with itself for the following matrices. Also, write a MATLAB code to eliminate the
second row of the matrix and interchange the first column with the third column.
2 1 0
[1 1 1]
0 0 2
MATLAB CODE:

clc
clear all

a = [2 1 0;
1 1 1;
0 0 2];

fprintf("Given Matrix: %s \n \n", mat2str(a));

fprintf("Transpose Matrix: %s \n \n", mat2str(transpose(a)));

fprintf("Inverse Matrix: %s \n \n", mat2str(inv(a)));

fprintf("Determminant of Matrix: %d \n \n", det(a));

fprintf("Eigenvalue Matrix: %s \n \n", mat2str(eig(a)));

fprintf("Rank of Matrix: %s \n \n", mat2str(rank(a)));

fprintf("Upper triangluar Matrix: %s \n \n", mat2str(triu(a)));

fprintf("Lower triangular Matrix: %s \n \n", mat2str(tril(a)));

fprintf("Addition with itself: %s \n \n", mat2str(a+a));

fprintf("Subtraction with itself: %s \n \n", mat2str(a-a));

fprintf("Multiplication with itself: %s \n \n", mat2str(a*a));

%Eliminating second row


a(2,:) = [];

fprintf("Matrix after eliminating 2nd row : %s \n\n", mat2str(a));

%Interchanging 1st column with 3rd column


col1 = a(:,1);
a(:,1) = a(:,3);
a(:,3) = col1;
fprintf("Matrix after interchanging 1st column with 3rd column : %s \n\n", mat2str(a));
OUTPUT:
QUESTION 4:

Find the transpose, inverse, determinant, eigenvalues, rank, lower triangular matrix, upper
triangular matrix, and perform matrix addition, subtraction, and multiplication with itself for
the following matrices. Also write a MATLAB code for pulls out the second column and third
row.
5 1 1
[0 6 0]
1 3 0
MATLAB CODE:

clc
clear all

a = [5 1 1;
0 6 0;
1 3 0];

fprintf("Given Matrix: %s \n \n", mat2str(a));

fprintf("Transpose Matrix: %s \n \n", mat2str(transpose(a)));

fprintf("Inverse Matrix: %s \n \n", mat2str(inv(a)));

fprintf("Determminant of Matrix: %d \n \n", det(a));

fprintf("Eigenvalue Matrix: %s \n \n", mat2str(eig(a)));

fprintf("Rank of Matrix: %s \n \n", mat2str(rank(a)));

fprintf("Upper triangluar Matrix: %s \n \n", mat2str(triu(a)));

fprintf("Lower triangular Matrix: %s \n \n", mat2str(tril(a)));

fprintf("Addition with itself: %s \n \n", mat2str(a+a));

fprintf("Subtraction with itself: %s \n \n", mat2str(a-a));

fprintf("Multiplication with itself: %s \n \n", mat2str(a*a));

fprintf("Second column of matrix: %s \n\n", mat2str(a(:, 2)));


fprintf("Third column of matrix: %s \n\n", mat2str(a(:, 3)));
OUTPUT:

Common questions

Powered by AI

In MATLAB, matrix subtraction can be performed using `-`. For the matrix \([1, 1, 1; 1, -1, 2; 1, 1, 1]\), subtracting it from itself, i.e., `a-a`, results in a zero matrix \([0, 0, 0; 0, 0, 0; 0, 0, 0]\).

The rank of the matrix \([5, 1, 1; 0, 6, 0; 1, 3, 0]\) is determined using MATLAB's `rank` function, which indicates the number of linearly independent rows or columns. The matrix has a rank of 3, indicating all rows (or columns) are linearly independent .

Eliminating the third column from the matrix \([3, 0, 2; 2, 0, -2; 0, 1, 1]\) results in \([3, 0; 2, 0; 0, 1]\). Interchanging the first and third rows of this new matrix results in \([0, 1; 2, 0; 3, 0]\).

The inverse of matrix \([3, 0, 2; 2, 0, -2; 0, 1, 1]\) can be found using MATLAB's `inv` function. An inverse exists only when the matrix is square and its determinant is non-zero, which is true in this case as the determinant is 6. The inverse is approximately \([0.2, -0.2, 0.2; -0.2, 0.3, 0.0; 0.2, 0.3, 0.0]\).

In MATLAB, a 4x4 identity matrix can be created using the command `eye(4);`, and a 4x4 matrix of zeros can be created using `zeros(4);` .

The upper triangular matrix of \([2, 1, 0; 1, 1, 1; 0, 0, 2]\) can be created using MATLAB's `triu` function. The resulting matrix is \([2, 1, 0; 0, 1, 1; 0, 0, 2]\).

The MATLAB code to interchange the first column with the third column of the matrix \([2, 1, 0; 1, 1, 1; 0, 0, 2]\) is: ```MATLAB col1 = a(:,1); a(:,1) = a(:,3); a(:,3) = col1; ``` This code swaps the first and third columns .

The determinant of the matrix \([0, 6, 0; 1, 3, 0; 5, 1, 1]\) can be calculated using MATLAB's `det` function. It evaluates to -12 .

Using MATLAB's `eig` function, the eigenvalues of the matrix \([2, 1, 1; 1, 1, 1; 1, -1, 2]\) can be calculated. The eigenvalues are approximately \([3, 1.5, 0.5]\).

To remove the second row of the matrix \([2, 1, 0; 1, 1, 1; 0, 0, 2]\) in MATLAB, use the command `a(2,:) = [];`. This results in the matrix \([2, 1, 0; 0, 0, 2]\).

You might also like