Solving System of Linear Equations

A system of linear equations is a collection of linear equations involving the same set of variables.

For example:
5x + 2y – 3z = 1
-2x – y + 7z = 8
4x – 13y + z = -10

is a system of three equations in the three variables x, y and z.

A general form of system of m linear equations with n unknowns can be written as:

a11x1 + a12x2 + a13x3 + … + a1nxn = b1
a21x1 + a22x2 + a23x3 + … + a2nxn = b2
… … … …
am1x1 + am2x2 + am3x3 + … + amnxn = bm

From above system of linear equations, x1, x2, x3, …, xn are unknown, a11, a12, a13, … amn are coefficients of the system, and b1, b2, b3, …, bn are the constant terms. If all constant terms are zero, the system of linear equations is called homogeneous system (see Solving Homogeneous System).

Matrix Equation

The system of linear equations is equivalent to a matrix equation of the form

AX=B
Where:
A is m x n matrix of coefficients. Element of matrix A at i th-row and j th-column is aij.
X is n x 1 matrix (column vector with n entries). Element of matrix X at i th-row is xi.
B is m x 1 matrix (column vector with m entries). Element of matrix B at i th-row is bi.

 

Solving with MathPACK Solver

MathPACK Solver can solve the system of linear equations for finding the values of unknowns (matrix X) by using linsolve function. The system of linear equations must be written in the form of Matrix Equation described in previous section and the number of linear equations must be equal to number of unknowns (A must be square matrix : m = n).

Function Signature

X = linsolve(A, B);

Example

5x + 2y – 3z = 1
-2x – y + 7z = 8
4x – 13y + z = -10
So, the following expressions must be executed in MathPACK Solver console

»A = [5, 2, -3; -2, -1,7; 4, -13, 1]; 
»B = [1; 8; -10]; 
»X = linsolve(A, B) 
ans = 
    0.6571  
    1.0857  
    1.4857 
 
So, the solution will be:
x = 0.6571
y = 1.0857
z = 1.4857
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply