Simultaneous Equation Solver


Please enter the number of variables:

How it works

The coefficients are put into a matrix A, the variables into a vector v and the constants into a vector c.
i.e. Av = c
The inverse of A is then multiplied through the equation.
A-1Av = A-1c
v = A-1c
The variables can then be found by multiplying A-1 by c.


Finding A-1

A-1 = adj(A)/det(A), where adj(A) is the adjugate matrix of A and det(A) is the determinant of A.

Finding the determinant

The determinant of a matrix can be found by multiplying each element in any given row of the matrix by the minor of the element. These are then added if the element's indices are both even or odd, or subtracted if the element's indices are not both odd/even.
The process of finding a determinant is therefore iterative and is done recursively in this script.
Important note: A determinant of 0 indicates that the system of equations has no unique solution (no solutions or an infinite number of solutions).

Finding the adjugate matrix

The adjugate of a matrix is the transpose of the cofactor matrix.
The cofactor of each element in a matrix is found by the minor matrix to the element and then, similarly to when finding the determinant, multiplying by -1 if the element's indices are not both odd/even.
The cofactor matrix is then transposed (rows and columns are switched) to find the adjugate.

Finding the inverse matrix

The adjugate can then be divided by the determinant to find the inverse matrix.


Finding variables

v = A-1c
The multiplication is then carried out in order to find the value of each variable.


An example

2x + y - z = 5
3x - y + 2z = -1
x - y - z = 0


Step 1: Set up matrix and vectors

2 1 -1
3 -1 2
1 -1 -1
    
x
y
z
    
=
    
5
-1
0

Av = c
A-1Av = A-1c
v = A-1c


Step 2: Find A-1

A-1 = adj(A)/det(A)

Finding adj(A)

The minor matrix for the top left element can be found by ignoring the column and row the element is in and taking the determinant of the remaining matrix.

2 1 -1
3 -1 2
1 -1 -1

The minor for the top left element is therefore the determinant of
-1 2
-1 -1
  
= (-1)(-1) - 2(-1) = 1 + 2 = 3

The cofactor of the top left element is just the minor since the indices of the element are 1 1 which are both odd. This process can be repeated to obtain the following cofactor matrix:
C =  
3 5 -2
2 -1 3
1 -7 -5


adj(A) = CT =   
3 2 1
5 -1 -7
-2 3 -5

Finding A-1

A-1 = adj(A)/det(A)
det(A) = 13
adj(A) =   

3 2 1
5 -1 -7
-2 3 -5


A-1 =   
3/13 2/13 1/13
5/13 -1/13 -7/13
-2/13 3/13 -5/13


Step 3: Solving for variables

v = A-1c

x
y
z
    
=
    
3/13 2/13 1/13
5/13 -1/13 -7/13
-2/13 3/13 -5/13
    
5
-1
0

The matrix can then be multiplied with the vector to get:

x
y
z
    
=
    
1
2
-1

Solutions

x = 1
y = 2
z = -1