Assignment No: 1
Topic: To determine the rank of a matrix and use it to solve a system of linear
equations using MATLAB
Steps to create a Matrix in MATLAB
Defining a matrix is similar to defining a vector. To define a matrix A, you can treat it like a
column of row vectors. That is, you enter each row of the matrix as a row vector (remember to
separate the entries either by commas or spaces) and you separate the rows by semicolons (;).
A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
Here, A is a 3x3 matrix.
1. To Create a 2x3 matrix of zeros use
B = zeros (2, 3);
2. To Create a 4x2 matrix of ones use
C = ones (4, 2);
3.To Create a 3x3 identity matrix use
I = eye (3);
4. To create the scalar matrix of order n
M = k * eye(n)
5.To create a column vector
B = [5; -8; 4]
Much of MATLAB’s power comes from its matrix functions. These can be further separated into
two sub-categories. The first one consists of convenient matrix building functions, some of which
are given in the table below.
Sr. No. Function Description
Eye Identity matrix
zeros Matrix of zeroes
ones Matrix of ones
diag Extract diagonal of a matrix or create diagonal matrices
Triu Upper triangular part of a matrix
Tril Lower triangular part of a matrix
rand Randomly generated matrix
II If A is an invertible square matrix and B is a compatible vector then
x = A\B is the solution of A x = B
Where A is coefficient Matrix of order m x n
B is the right-hand side vector of order m x 1
X is the vector of unknowns
To find rank of a matrix A use
rank_A = rank(A)
III Condition for Consistency
IV To find rank of [A|B] use the function rank ([A, B])
Note - We can attach a column to matrix A by using the function [A, B] if
the column has the same number of rows as matrix A.
V Steps to find solution of system of linear equations when it has
unique solution
Step -1 Define the coefficient matrix A and constants vector B
Step -2 Check the rank of matrix A
Step-3 Check the rank of the augmented matrix [A | B]
Step -4 Determine number of variables (n) by using function “size(A,2)”
Step -5 Checks if the system has a unique solution
Step -6 Solve using matrix division (i.e. x= A\B)
Step -7 Display the solution
Step-8 Else Display the system either has no solution or infinite solutions.
VI Steps to find solution of system of linear equations when it has infinitely many solution
Step -1 Enter the given system of linear equations.
Step-2 Find augmented matrix [A | B] by using function “equationsToMatrix”
Step -3 Check the rank of matrix A
Step-4 Check the rank of the augmented matrix [A | B]
Step -5 Determine number of variables (n) by using function “size(A,2)”
Step -6 Checks if the system has infinitely many solutions
Step -7 Solve using the function “solve”
Step -8 Display the solution
Step-9 Else Display the system either has no solution or infinite solutions.
VII Steps to find solution of system of linear equations when it has no
solution
Step -1 Enter the given system of linear equations.
Step-2 Find augmented matrix [A | B] by using function “equationsToMatrix”
Step -3 Check the rank of matrix A
Step-4 Check the rank of the augmented matrix [A | B]
Step -5 Determine number of variables (n) by using function “size(A,2)”
Step -6 If rank of matrix A is not equal to rank of matrix [A | B] then display system has no
solution
Examples
A) Find Rank of following matrices using MATLAB:
1 2 5 3
3 3 4
1. A=[2 −3 4] 2. A= [ 4 −3 1 0]
−2 3 6 7
0 −1 1
0 2 4 6
6 −2 3
5 −2 3
3 A=[ ] 4. A=[2 1 −2]
0 1 5
3 0 −1
1 6 4 0
5. A= [3 2 2 −1]
1 3 4 −1
B) Solve Following System of Linear Equation using concept of rank of the matrix:
Solve following system of linear equation using MATLAB
1. 3𝑥 + 4𝑦 − 𝑧 = 2, 2𝑥 − 𝑦 + 3𝑧 = 1, 𝑥 + 2𝑦 + 𝑧 = 3
2. 𝑥 + 𝑦 − 𝑧 = 2 , 2𝑥 + 2𝑦 − 2𝑧 = 4, 3𝑥 + 3𝑦 − 3𝑧 = 6
3. 𝑥 + 2𝑦 − 𝑧 + 𝑤 = 4, 2𝑥 + 4𝑦 − 2𝑧 + 2𝑤 = 8, 𝑥 − 𝑦 + 𝑧 = 1
4. 5𝑥 + 2𝑦 − 𝑧 = 3, 2𝑥 + 4𝑦 − 2𝑦 = 7, 3𝑥 + 6𝑦 − 3𝑧 = 10
5. 𝑥 + 2𝑦 + 2𝑧 = 1, 2𝑥 + 2𝑦 + 3𝑧 = 3, 𝑥 − 𝑦 + 3𝑧 = 5
6. 2𝑥 − 3𝑦 + 5𝑧 = 1, 3𝑥 + 𝑦 − 𝑧 = 2, 𝑥 + 4𝑦 − 6𝑧 = 1