Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
System of Linear Equations | Linear Algebra
Mathematics for Data Analysis and Modeling
course content

Contenido del Curso

Mathematics for Data Analysis and Modeling

Mathematics for Data Analysis and Modeling

1. Basic Mathematical Concepts and Definitions
2. Linear Algebra
3. Mathematical Analysis

bookSystem of Linear Equations

A system of linear equations (SLE) is a set of equations where each equation is a linear combination of variables. The goal is to find a solution that satisfies all the equations simultaneously.

Example

Let's look at the example of a system of linear equations:

We have 3 unknown variables x, y and z and have 3 equations that include all of these variables.

Solving the system

How can we solve the system? Firstly, let's rewrite it in a matrix form:

Expressing the system of linear equations in matrix form provides us with a straightforward approach for solving the system utilizing the inverse matrix:

To use this approach we have to be sure that matrix A can be inversed:
The square matrix A can be inversed if and only if its determinant is nonzero.

Example 1

1234567891011121314151617181920
import numpy as np # Define the coefficients matrix A A = np.array([[2, 3, -1], [4, -1, 2], [1, 2, -3]]) # Define the constants vector н y = np.array([10, 4, -1]) # Check the determinant of matrix A print(f'Determinant is {round(np.linalg.det(A), 3)}') # Calculating inversed matrix A_inv = np.linalg.inv(A) # Finding solution using inversed matrix x = np.dot(A_inv, y) # Print the solution print(f'Solution: {np.round(x, 3)}')
copy

We have found the solution using the inverted matrix.

Example 2

1234567891011121314151617
import numpy as np # Define the coefficients matrix A A = np.array([[1, 2, 3], [3, 1, 4], [4, 3, 7]]) # Define the constants vector b b = np.array([10, 20, 30]) # Check the determinant of matrix A det_A = np.linalg.det(A) # Print the determinant value print(f'Determinant of A: {det_A}') A_inv = np.linalg.inv(A)
copy

The code above produces an error - the matrix is singular (has zero determinant) so we can't solve the system of equations.
The explanation for this is quite simple: the matrix rows are linearly dependent (the third row is the sum of the first two). As a result, the third equation doesn't provide any additional information, and we are left with a system of 3 variables but only 2 unique equations. As a result such a system either have no solutions or there are lots of solutions.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 7
We're sorry to hear that something went wrong. What happened?
some-alt