Linear Algebra

Matrix Calculator

Add, multiply, determinant, inverse, rank, row-echelon form and solving linear systems — exact with fractions and step-by-step.

Matrix A
Rows2
Columns2
Matrix B
Rows2
Columns2

Explanation

What this tool does

The matrix calculator works over the rational numbers: every entry is kept as an exact fraction, so results are exact — 1/3 never drifts to 0.3333. Enter a matrix, pick an operation, and (where it helps) read the worked steps.

Core operations

For matrices AA and BB of compatible sizes:

(A+B)ij=Aij+Bij,(AB)ij=kAikBkj.(A + B)_{ij} = A_{ij} + B_{ij}, \qquad (AB)_{ij} = \sum_{k} A_{ik} B_{kj}.

Matrix multiplication is not commutativeABAB and BABA usually differ — so both are offered.

Gaussian elimination

Row reduction underlies rank, the determinant, the inverse, and solving systems. Each step is one of three elementary row operations: swap two rows, scale a row, or add a multiple of one row to another. Reducing to reduced row-echelon form (a leading 1 in each pivot column, zeros elsewhere in that column) exposes the rank and the solution set.

Determinant

Reducing AA to upper-triangular form by row operations, the determinant is the product of the diagonal, with a sign flip for each row swap:

det(A)=(1)siuii.\det(A) = (-1)^{s} \prod_i u_{ii}.

A zero on the diagonal after elimination means det(A)=0\det(A) = 0 and AA is singular.

Inverse

Augment AA with the identity and run Gauss–Jordan elimination: [AI][IA1][\,A \mid I\,] \to [\,I \mid A^{-1}\,]. If the left block cannot reach II, the matrix is singular and has no inverse.

Solving Ax=bAx = b

Row-reduce the augmented matrix [Ab][\,A \mid b\,]. A pivot in the bb column means no solution. Otherwise the pivots fix the basic variables; any free columns give a null-space basis, so the full solution is one particular vector plus any combination of those basis vectors.

Worked example

With A=[2113]A = \begin{bmatrix} 2 & 1 \\ 1 & 3 \end{bmatrix} and b=[34]b = \begin{bmatrix} 3 \\ 4 \end{bmatrix}, elimination gives the unique solution x=[11]x = \begin{bmatrix} 1 \\ 1 \end{bmatrix}, and det(A)=5\det(A) = 5.

Number domains

The number domain selector changes what an entry is. The same operations run over each, because the engine is written against an abstract field:

  • Fractions — exact rationals (the default).
  • Complex numbers — exact Gaussian rationals a+bia + b\,i with rational a,ba, b. Closed under +,,×,÷+,-,\times,\div (divide by the conjugate), so the determinant, inverse, RREF and solver stay exact. Enter cells like 3+2i, -i, or 1/2 - 3/4 i.
  • Symbolic — entries may contain variables (a, 2x, x^2, (x+1)/(x-1)). Values are multivariate rational functions over Q\mathbb{Q}, which form a field, so det[abcd]=adbc\det\begin{bmatrix} a & b \\ c & d \end{bmatrix} = ad - bc and [a00b]1=[1/a001/b]\begin{bmatrix} a & 0 \\ 0 & b \end{bmatrix}^{-1} = \begin{bmatrix} 1/a & 0 \\ 0 & 1/b \end{bmatrix} come out symbolically. Pivots are taken in generic position (a symbolically-nonzero entry is treated as nonzero), and results are simplified conservatively — never wrongly.

Decompositions

  • LUPA=LUPA = LU with a lower-triangular LL, an upper-triangular UU, and a permutation PP recording row swaps. Exact over any domain.
  • QRA=QRA = QR with orthonormal QQ and upper-triangular RR (Gram–Schmidt). Needs square roots, so it is numeric (approximate).
  • Cholesky — for a symmetric positive-definite AA, A=LLTA = LL^{\mathsf T}. Also numeric, and reported as not-SPD when no such factor exists.

Spectrum

The characteristic polynomial det(λIA)\det(\lambda I - A) is computed exactly by the Faddeev–LeVerrier recurrence over any domain. Eigenvalues are its roots: exact when they are rational, otherwise found numerically (so a rotation matrix [0110]\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} reports ±i\pm i, flagged approximate). Each eigenvector spans the null space of AλIA - \lambda I, exact for rational λ\lambda and numeric otherwise.

Results that cannot be exact are marked approximate so the distinction is never hidden.