How to Solve Linear Equations with Matrix Inversion
Deepak Raj
Posted on August 18, 2023
In this article, we will solve linear equations using inverse matrix using Python and Numpy.
We will solve linear equations using an inverse matrix in two steps. First, we will find the inverse of the matrix and then we will multiply the inverse matrix with the constant matrix.
For this, we will take an example of two linear equations with two variables. we will solve to find the value of x and y.
What is Linear Equation?
A linear equation is an equation of a straight line. It is a polynomial equation of degree 1. A linear equation can have more than one variable.
Standard Form of Linear Equation
The standard form of the linear equation is given below.
Example of Linear Equation
How to Solve Linear Equations with Matrix Inversion? | Mathematics
A = [[3, 8],
[4, 11]]
B = [5, 7]
X = ?
X = inverse(A) . B
How to Find Inverse of Matrix? | Python
Here is the Python code to find the value of x and y using an inverse matrix using Python and Numpy.
First, we will check if the matrix is invertible or not. If the matrix is invertible then we will find the inverse of the matrix and then we will multiply the inverse matrix with the constant matrix to find the value of x and y.
Driver Code
It’s time to test our code. Here is the driver code to test our code.
def test_case():
A = np.array([[3, 8], [4, 11]])
B = np.array([5, 7])
solver = LinearEquationSolver(A, B)
coff = solver.solve()
print(coff)
if __name__ == " __main__":
test_case()
Output
[-1. 1.]
Explanation
Here is the explanation of the output.
Conclusion
In this article, we learned how to solve linear equations using an inverse matrix. We learned how to find the inverse of the matrix and how to multiply the inverse matrix with the constant matrix to find the value of x and y.
Posted on August 18, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.