Case B: m>n
Solution for the this type of linear equation can be find out using
Example 1:
Consider the system of linear equation:
Implementations
Python3
import numpy as np # A 2 x 2 matrix A = np.array([[ 1 , 2 ], [ 3 , 7 ], [ 4 , 9 ]]) b = np.array([ 5 , 10 , 15 ]) # Solution def solution(A,b): A_trans = A.T sol = np.linalg.inv(A_trans@A)@A_trans@b return sol solution(A,b) |
Output:
array([15., -5.])
Check the solutions
Python3
# Ax=b A@solution(A,b) |
Output:
array([ 5., 10., 15.])
Example 2:
Consider the system of linear equation:
Implementations
Python3
import numpy as np # A 2 x 2 matrix A = np.array([[ 1 , 3 ], [ 3 , 8 ], [ 4 , 10 ]]) b = np.array([ 5 , 10 , 15 ]) # Solution def solution(A,b): A_trans = A.T sol = np.linalg.inv(A_trans@A)@A_trans@b return sol solution(A,b) |
Output:
array([2.22222222, 0.55555556])
Check the solutions
Python3
# Ax=b A@solution(A,b) |
Output:
array([ 3.88888889, 11.11111111, 14.44444444])
Data Science – Solving Linear Equations with Python
A collection of equations with linear relationships between the variables is known as a system of linear equations. The objective is to identify the values of the variables that concurrently satisfy each equation, each of which is a linear constraint. By figuring out the system, we can learn how the variables interact and find hidden relationships or patterns. In disciplines including physics, engineering, economics, and computer science, it has a wide range of applications. Systems of linear equations can be solved quickly and with accurate results by using methods like Gaussian elimination, matrix factorization, inverse matrices and Lagrange function.
This is implemetations part of Data Science | Solving Linear Equations