Escolar Documentos
Profissional Documentos
Cultura Documentos
In Gauss-Jordan elimination method, we first transfer the Linear Equation System (LES) to a matrix
system. Then, after applying necessary elementary row operations, we try to achieve a matrix which consists of
an Identity matrix in the first part and the solution column in the second part. Therefore, we may find the
solution directly by this solution column. For example,
1
[m,n] = size(A);
% All row operations
% Downwards
for i=1:m
A(i,:) = A(i,:)/A(i,i);
for j=(i+1):m
A(j,:) = A(j,:)+(-1)*A(j,i)*A(i,:);
end
end
%Upwards
for i=m:-1:1
for j=(i-1):-1:1
A(j,:) = A(j,:) + (-1)*A(j,i)*A(i,:);
end
end
%Finding the values
x = []; % Solution vector
for i=1:m
x(i) = A(i,n);
end
1 0 0 ∶ 1 −1 1 1 −1 1
𝑅1 →𝑅1 +(−1/3)𝑅3
→ [ 0 1 0 ∶ 0 2 −1] ⇒ 𝐴−1 = [0 2 −1]
0 0 1 ∶ 2 3 0 2 3 0
Here the matrix D is also the inverse of matrix A. It is calculated by the MATLAB function, inv(). This
function calculates the inverse of a matrix. In our example, both matrix C and D are the same which shows that
we have calculated the inverse of matrix A correct. ☺
The generalized form of it:
3
%Inverse
C = B(:,(n/2)+1:n);
3. Inverse of a Matrix by Adjoint Matrix in MATLAB
This is how we get the inverse of a matrix by Adjoint Matrix:
1
𝐴−1 = . 𝑎𝑑𝑗(𝐴)
|𝐴|
Here |𝐴| is the determinant of matrix A and 𝑎𝑑𝑗(𝐴) is the adjoint matrix of A.
Since we will be using MATLAB function det( ) for calculating the determinant of matrix A, we will
not deal with how to get the determinant in this lab notes. You may check your class notes for that.
However, we will be dealing with how to calculate 𝑎𝑑𝑗(𝐴). It is calculated as following:
𝑎𝑑𝑗(𝐴) = 𝐶 𝑇 ,
where 𝐶 𝑇 is the transpose of the coefficients matrix of A. And 𝐶 𝑇 is calculated as such:
𝐶 = (−1)𝑖+𝑗 . 𝑀
where 𝑀 is the minors matrix. We calculate it as this:
𝑚𝑖𝑗 = |𝐵|
where 𝑚𝑖𝑗 is the elements of matrix 𝑀, and 𝐵 is the matrix that is obtained by deleting the ith row and jth
column from matrix 𝐴.
Let us try to find the inverse of the matrix in previous example.
3 3 −1 3 3 −1
𝐴 = [−2 −2 1] ⇒ |𝐴| = |−2 −2 1| = 1
−4 −5 2 −4 −5 2
−2 1 −2 1 −2 −2
𝑚11 = | |=1 𝑚12 = | |=0 𝑚13 = | |=2
−5 2 −4 2 −4 −5
3 −1 3 −1 3 3
𝑚21 =| |=1 𝑚22 =| |=2 𝑚23 = | | = −3
−5 2 −4 2 −4 −5
3 −1 3 −1 3 3
𝑚31 =| |=1 𝑚32 =| |=1 𝑚33 = | |=0
−2 1 −2 1 −2 −2
1 0 2
Hence, matrix of minors is 𝑀 = [1 2 −3].
1 1 0
Now we can calculate the matrix of coefficients by the formula 𝐶 = (−1)𝑖+𝑗 . 𝑀
1 0 2 1 −1 1
Here is the matrix 𝐶 = [−1 2 3]. Then the transpose of it is 𝐶 𝑇 = [0 2 −1] = 𝑎𝑑𝑗(𝐴).
1 −1 0 2 3 0
1
Now the only thing we need to do it is to put all these together in the formula 𝐴−1 = |𝐴| . 𝑎𝑑𝑗(𝐴).
4
1 1 −1 1 1 −1 1
𝐴−1 = . [0 2 −1] = [0 2 −1]
1
2 3 0 2 3 0
As you can tell, this solution has given us the same solution in the previous method’s example.
Here are the MATLAB codes for this solution:
A = [3 3 -1
-2 -2 1
-4 -5 2];
determinant = det(A);
M = []; %Minor Matrix
M(1,1) = det(A([2 3],[2 3])); % A([2 3],[2 3]) means that we only get
2nd and 3rd rows and 2nd and 3rd columns in matrix A
M(1,2) = det(A([2 3],[1 3]));
M(1,3) = det(A([2 3],[1 2]));
M(2,1) = det(A([1 3],[2 3]));
M(2,2) = det(A([1 3],[1 3]));
M(2,3) = det(A([1 3],[1 2]));
M(3,1) = det(A([1 2],[2 3]));
M(3,2) = det(A([1 2],[1 3]));
M(3,3) = det(A([1 2],[1 2]));
M
C = []; % Cofactor Matrix
for i=1:3
for j=1:3
C(i,j) = ((-1)^(i+j)) * M(i,j);
end
end
C
adjointA = transpose(C);
adjointA
B = (1/determinant) * adjointA;
B
inv(A)