Please enter the number of variables:

(Any boxes left blank will be autofilled with 0)

The coefficients are put into a matrix A, the variables into a vector **v** and the constants into a vector **c**.

i.e. A**v** = **c**

The inverse of A is then multiplied through the equation.

A^{-1}A**v** = A^{-1}**c**

**v** = A^{-1}**c**

The variables can then be found by multiplying A^{-1} by **c**.

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

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).**

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.

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

**v** = A^{-1}**c**

The multiplication is then carried out in order to find the value of each variable.

2x + y - z = 5

3x - y + 2z = -1

x - y - z = 0

2 | 1 | -1 |

3 | -1 | 2 |

1 | -1 | -1 |

x |

y |

z |

= |

5 |

-1 |

0 |

A**v** = **c**

A^{-1}A**v** = A^{-1}**c**

**v** = A^{-1}**c**

A^{-1} = adj(A)/det(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 |

3 | 2 | 1 |

5 | -1 | -7 |

-2 | 3 | -5 |

A^{-1} = adj(A)/det(A)

det(A) = 13

adj(A) =

3 | 2 | 1 |

5 | -1 | -7 |

-2 | 3 | -5 |

3/13 | 2/13 | 1/13 |

5/13 | -1/13 | -7/13 |

-2/13 | 3/13 | -5/13 |

**v** = A^{-1}**c**

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 |

**
x = 1
y = 2
z = -1
**