VOOZH about

URL: https://www.geeksforgeeks.org/python/data-science-solving-linear-equations-2/

⇱ Data Science - Solving Linear Equations with Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Data Science - Solving Linear Equations with Python

Last Updated : 12 Jul, 2025

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

Generalized linear equations

Generalized linear equations are represented as below:

Ax=b

Where,

  • A is an mXn matrix
  • x is nX1 variables or unknown terms
  • b is the dependent variable mX1
  • m & n are the numbers of equations and variables

In general, there are three cases one needs to understand: 

👁 System of Linear Equations-Geeksforgeeks
System of Linear Equations

Case A: m=n

Solution for the this type of linear equation can be find out using

Example 1

Consider the system of linear equation:

implementations

Output:

Rank of the matrix is: 2
Inverse of A:
[[-7. 3.]
[ 5. -2.]]
Solution of linear equations:
[-19. 15.]
array([-19., 15.])

Example 2:

Consider the system of linear equation:

implementations

Output:

'infinite solution'

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

Output:

array([15., -5.])

Check the solutions

Output:

array([ 5., 10., 15.])

Example 2:

Consider the system of linear equation:

Implementations

Output:

array([2.22222222, 0.55555556])

Check the solutions

Output:

array([ 3.88888889, 11.11111111, 14.44444444])

Case C: m < n

Solution for the this type of linear equation can be find out using

Example C.1:

Consider the system of linear equation:

Implementations

Output:

array([2., 3., 4.])

Check the solutions

Output:

array([20., 38.])

Example C.2:

Consider the system of linear equation:

Implementations

Output:

array([0.36021505, 1.01075269, 4.12365591])

Check the solutions

Output:

array([23., 35.])
Comment
Article Tags: