A linear system is said to be square if the number of equations matches the number of unknowns. If the system $A x = b$ is square, then the coefficient matrix, $A$, is square. If $A$ has an inverse, then the solution to the system $A x = b$ can be found by multiplying both sides by $A ^{−1}$
$Ax=b$
$A^{-1}Ax=A^{-1}b$
$x=A^{-1}b$
If $A$ is an invertible $n$ by $n$ matrix, then the system $A x = b$ has a unique solution for every $n$‐vector $b$, and this solution equals $A ^{−1} b$.
Since the determination of $A^{ −1}$ typically requires more calculation than performing Gaussian elimination and back substitution, this is not necessarily an improved method of solving $A x = b$ (And, of course, if $A$ is not square, then it has no inverse, so this method is not even an option for non square systems.).However, if the coefficient matrix $A$ is square, and if $A ^{−1}$ is known or the solution of $A x = b$ is required for several different $b$'s, then this method is indeed useful, from both a theoretical and a practical point of view.
The elementary row operations that characterize Gauss‐Jordan elimination can be applied to compute the inverse of a square matrix.
If $E$ is the elementary matrix that results when a particular elementary row operation is performed on $I$(Identity Matrix), then the product $EA$ is equal to the matrix that would result if that same elementary row operation were applied to $A$. In other words, an elementary row operation on a matrix $A$ can be performed by multiplying $A$ on the left by the corresponding elementary matrix.
Thus the sequence of elementary matrix product will give the identity matrix $E_n...E_2E_1A=I$. where the elementary transformation matrix $E_n....E_2E_1$ will represent $A^{-1}$
We can solve the equation using an augmented notation
$[A|I_n] \ldots \ldots [I_n|A^{-1}]$
This means that , if we bring the augmented equation system into reduced row echelon form, we can read out the inverse on the right hand side of the equation system.Hence determining the inverse of a matrix is equivalent to solving system of linear equations.
Example:
Determine the inverse of the matrix
The augmented matrix is
Since the transformation [ A | I] → [ I | A −1] reads
So the inverse of the matrix A is
Python Program
# Importing NumPy Library
import numpy as np
import sys
# Reading order of matrix
n = int(input('Enter order of matrix: '))
# Making numpy array of n x 2n size and initializing
# to zero for storing augmented matrix
a = np.zeros((n,2*n))
# Reading matrix coefficients
print('Enter Matrix Coefficients:')
for i in range(n):
for j in range(n):
a[i][j] = float(input( 'a['+str(i)+']['+ str(j)+']='))
# Augmenting Identity Matrix of Order n
for i in range(n):
for j in range(n):
if i == j:
a[i][j+n] = 1
# Applying Guass Jordan Elimination
for i in range(n):
if a[i][i] == 0.0:
sys.exit('Divide by zero detected!')
for j in range(n):
if i != j:
ratio = a[j][i]/a[i][i]
for k in range(2*n):
a[j][k] = a[j][k] - ratio * a[i][k]
# Row operation to make principal diagonal element to 1
for i in range(n):
divisor = a[i][i]
for j in range(2*n):
a[i][j] = a[i][j]/divisor
# Displaying Inverse Matrix
print('\nINVERSE MATRIX IS:')
for i in range(n):
for j in range(n, 2*n):
print(a[i][j], end='\t')
print()
Enter order of matrix: 4 Enter Matrix Coefficients: a[0][0]=1 a[0][1]=0 a[0][2]=2 a[0][3]=0 a[1][0]=1 a[1][1]=1 a[1][2]=0 a[1][3]=0 a[2][0]=1 a[2][1]=2 a[2][2]=0 a[2][3]=1 a[3][0]=1 a[3][1]=1 a[3][2]=1 a[3][3]=1 INVERSE MATRIX IS: -1.0 2.0 -2.0 2.0 1.0 -1.0 2.0 -2.0 1.0 -1.0 1.0 -1.0 -1.0 0.0 -1.0 2.0
sympy code
from sympy import Matrix
M = Matrix(4, 4, [1, 0,0, 1, 0, 2, 1, 2, 2,1,0,1,2,0,1,4])
print(M.inv())
$\begin{bmatrix}
1 & 0 & 1 & 0\\
0 & 1 & 1 & 0\\
1 & 1& 0 & 1\\
1 & 1& 1 & 0
\end{bmatrix}$
Augmented matrix $AI$
$\begin{bmatrix}
1 & 0 & 1 & 0 &|& 1 &0 & 0 & 0\\
0 & 1 & 1 & 0&|& 0 & 1 & 0 & 0\\
1 & 1& 0 & 1&| & 0 & 0 & 1 & 0\\
1 & 1& 1 & 0 &|& 0 & 0 & 0 & 1
\end{bmatrix}$
$R_3=R_3-R_1, R_4=R_4-R_1$
$\begin{bmatrix}
1 & 0 & 1 & 0 &|& 1 &0 & 0 & 0\\
0 & 1 & 1 & 0&|& 0 & 1 & 0 & 0\\
0 & 1& -1 & 1&| & -1 & 0 & 1 & 0\\
0 & 1& 0 & 0 &|& -1 & 0 & 0 & 1
\end{bmatrix}$
$R_2=R_2-R_4, R_3=R_3-R_4$
$\begin{bmatrix}
1 & 0 & 1 & 0 &|& 1 &0 & 0 & 0\\
0 & 0 & 1 & 0&|& 1 & 1 & 0 & -1\\
0 & 0& -1 & 1&| & 0 & 0 & 1 & -1\\
0 & 1& 0 & 0 &|& -1 & 0 & 0 & 1
\end{bmatrix}$
Swap $R_2$ and $R_4$$\begin{bmatrix}
1 & 0 & 1 & 0 &|& 1 &0 & 0 & 0\\
0 & 1& 0 & 0 &|& -1 & 0 & 0 & 1\\
0 & 0& -1 & 1&| & 0 & 0 & 1 & -1\\
0 & 0 & 1 & 0&|& 1 & 1 & 0 & -1\\
\end{bmatrix}$
$R_1=R_1-R_4$, $R_3=R_3+R_4$$\begin{bmatrix}
1 & 0 & 0 & 0 &|& 0 &-1 & 0 & 1\\
0 & 1& 0 & 0 &|& -1 & 0 & 0 & 1\\
0 & 0& 0 & 1&| & 1 & 1 & 1 & -2\\
0 & 0 & 1 & 0&|& 1 & 1 & 0 & -1\\
\end{bmatrix}$
swap $R_3$ and $R_4$$\begin{bmatrix}
1 & 0 & 0 & 0 &|& 0 &-1 & 0 & 1\\
0 & 1& 0 & 0 &|& -1 & 0 & 0 & 1\\
0 & 0 & 1 & 0&|& 1 & 1 & 0 & -1\\
0 & 0& 0 & 1&| & 1 & 1 & 1 & -2\\
\end{bmatrix}$
So the inverse is$\begin{bmatrix}
0 &-1 & 0 & 1\\
-1 & 0 & 0 & 1\\
1 & 1 & 0 & -1\\
1 & 1 & 1 & -2\\
\end{bmatrix}$
Determine the inverses of the following matrix using Gaussian elimination method.Show all steps( university question)
$\begin{bmatrix}
1 & 0 & 0 & 1\\
0 & 2 & 1 & 2\\
2 & 1& 0 & 1\\
2 & 0& 1 & 4
\end{bmatrix}$
Determine the inverses of the following matrix if possible ( university question)
$\begin{bmatrix}
1 & 0 & 1 & 0\\
0 & 1 & 1 & 0\\
1 & 1& 0 & 1\\
1 & 1& 1 & 0
\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 & 1 & 1 & -2\\
\end{bmatrix}$
So the inverse is$\begin{bmatrix}
0 &-1 & 0 & 1\\
-1 & 0 & 0 & 1\\
1 & 1 & 0 & -1\\
1 & 1 & 1 & -2\\
\end{bmatrix}$
Determine the inverses of the following matrix using Gaussian elimination method.Show all steps( university question)
$\begin{bmatrix}
1 & 0 & 0 & 1\\
0 & 2 & 1 & 2\\
2 & 1& 0 & 1\\
2 & 0& 1 & 4
\end{bmatrix}$
Augmented matrix $AI$
$\begin{bmatrix}
1 & 0 & 0 & 1 &|& 1 &0 & 0 & 0\\
0 & 2 & 1 & 2&|& 0 & 1 & 0 & 0\\
2 & 1& 0 & 1&| & 0 & 0 & 1 & 0\\
2& 0& 1 & 4 &|& 0 & 0 & 0 & 1
\end{bmatrix}$
$\begin{bmatrix}
1 & 0 & 0 & 1 &|& 1 &0 & 0 & 0\\
0 & 2 & 1 & 2&|& 0 & 1 & 0 & 0\\
2 & 1& 0 & 1&| & 0 & 0 & 1 & 0\\
2& 0& 1 & 4 &|& 0 & 0 & 0 & 1
\end{bmatrix}$
$R3=R1 \times -2 + R3$
$R4=R1 \times -2 + R4$
$\begin{bmatrix}
1 & 0 & 0 & 1 &|& 1 &0 & 0 & 0\\
0 &1 & 1/2 & 1&|& 0 & 1/2 & 0 & 0\\
0 & 1& 0 & -1&| & -2 & 0 & 1 & 0\\
0& 0& 1 & 2 &|& -2 & 0 & 0 & 1
\end{bmatrix}$
$R3=R3-R2$
$\begin{bmatrix}
1 & 0 & 0 & 1 &|& 1 &0 & 0 & 0\\
0 &1 & 1/2 & 1&|& 0 & 1/2 & 0 & 0\\
0 & 0& -1/2 & -2&| & -2 &-1/2 & 1 & 0\\
0& 0& 1 & 2 &|& -2 & 0 & 0 & 1
\end{bmatrix}$
$R3=R3 \times -2$
$\begin{bmatrix}
1 & 0 & 0 & 1 &|& 1 &0 & 0 & 0\\
0 &1 & 1/2 & 1&|& 0 & 1/2 & 0 & 0\\
0 & 0&1 & 4&| & 4 &1 & -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0& 0& 0 & 1 &|& 3 & 1/2 & -1& -1/2
\end{bmatrix}$
The inverse is
$\begin{bmatrix}
-2 &-1/2 & 1 & 1/2\\
1& 1/2 &0 & -1/2\\
-8 &-1 & 2 & 2\\
3 & 1/2 & -1& -1/2
\end{bmatrix}$
Comments
Post a Comment