Math calculator

Matrix Decomposition Calculator

Factor it into pieces that are easy to work with.

Factor it into simpler pieces

LU is exact; QR and Cholesky take square roots.

Square.

2 × 2

A = LU

LU needs only arithmetic, so every entry here is exact.

A

The matrix being factored.
43
63

L

Lower triangular, holding the multipliers used during elimination.
10
1.51

U

Upper triangular — what elimination leaves behind.
43
0−1.5

Method

LU

exact on rationals

Row swaps

0

none needed

  • L holds the multipliers used during elimination and U is what elimination leaves behind. Multiplying them reconstructs the original matrix — permuted, when row swaps were needed.
  • The point of LU is reuse: once a matrix is factored, solving Ax = b for a new b is two triangular substitutions rather than a full elimination — which is why solvers factor once and solve many times.

Multiplying L by U reconstructs the original exactly, with no rounding to allow for.

What this tool shows

LU needs only arithmetic, so it stays exact. QR and Cholesky take square roots, so they are decimal — a matrix of whole numbers has an exact LU and an irrational QR. This page labels which is which rather than presenting them alike.

  • LU decomposition, exactly
  • QR by modified Gram-Schmidt
  • Cholesky for symmetric positive-definite matrices
  • Why pivoting makes it PA = LU
  • Why Cholesky failing is the useful answer
  • Which decomposition to use for what
Three methods LU stays exact Square roots flagged Positive-definite test

LU is exact; QR and Cholesky are decimal, and marked as such.

Updated 7 September 2026 · Works in any browser, no installation

Factoring turns one hard problem into two easy ones. A triangular system solves by substitution in a single pass, so writing A as a product of triangles means solving Ax = b becomes two passes rather than a full elimination — and the factorisation is reused for every new b.

At a glance

Formula shown
LU writes A as a lower triangle times an upper one, with a permutation when pivoting is needed. QR writes A as an orthonormal Q times an upper triangular R. Cholesky writes a symmetric positive-definite A as L times its own transpose.
Scenario support
Solving the same system with many right-hand sides; least-squares fitting; testing whether a matrix is positive definite; simulating correlated random variables.
Educational estimate
Planning support from the values you enter — not professional advice.

Why factor at all

Triangular systems are easy. The last equation has one unknown, so you solve it and substitute upwards. One pass, no searching.

General systems are not. Elimination is O(n³), and doing it again for every new right-hand side is wasteful when the matrix has not changed.

So: factor once, at O(n³), then every solve after that is two triangular substitutions at O(n²). With a hundred right-hand sides that is a very large saving, and it is exactly why numerical libraries factor rather than invert.

Each factorisation also exposes something. LU is elimination written down. QR produces an orthonormal basis. Cholesky proves positive definiteness on the way past.

LU and pivoting

LU is Gaussian elimination with the working kept. U is what elimination leaves behind; L holds the multipliers used to get there.

It is exact on this page, because elimination needs only addition, subtraction, multiplication and division — no square roots. A matrix of whole numbers has an LU with rational entries and nothing is rounded.

Not every matrix has one without pivoting. A zero in a pivot position stops the process, and the fix is to swap rows — which is why the general result is written PA = LU, with P recording the swaps.

In floating point, pivoting is done even when it is not strictly necessary: swapping the largest available entry into the pivot position keeps the multipliers small and the errors under control. On exact arithmetic that motivation disappears, and swaps are made only when a pivot is genuinely zero.

QR and the Gram-Schmidt trap

QR writes A as Q times R, where Q has orthonormal columns — each of length one, and each perpendicular to the others — and R is upper triangular.

Q being orthonormal is what makes it valuable: its inverse is simply its transpose, and multiplying by it neither stretches nor distorts, so it cannot amplify error.

The textbook construction is Gram-Schmidt: take each column, subtract off its projections onto the earlier ones, normalise. There are two versions of that, identical on paper.

Classical subtracts every projection from the original vector. Modified subtracts each projection from the running remainder. Algebraically the same; numerically not close. On nearly-dependent columns the classical version loses orthogonality badly, and Q comes back visibly not orthogonal.

This page uses the modified version and reports how far QᵀQ actually falls from the identity, so the quality of the result is visible rather than assumed.

QR is what least-squares solvers use. Forming the normal equations instead squares the condition number, which can throw away half the available precision on an awkward problem.

Cholesky, and what its failure tells you

For a symmetric positive-definite matrix, Cholesky writes A as L times its own transpose — one triangle, used twice.

Because the symmetry means only one triangle has to be computed, it is about half the work of a general LU. When it applies, it is the method to use.

The interesting part is what happens when it does not apply. The algorithm reaches a square root of a non-positive number and stops — and that failure is the definition. A symmetric matrix is positive definite exactly when Cholesky completes.

So attempting a Cholesky is the standard test for positive definiteness, and it is far cheaper than computing eigenvalues and checking their signs. A failure is a result rather than an error, which is why this page reports it as one.

It also has a neat guarantee behind it: AᵀA is positive definite for every A with independent columns, which is why Cholesky is what least-squares and simulation code reach for.

Which one to use

LU for solving square systems, especially with several right-hand sides. The general workhorse.

QR for least squares, for orthonormal bases, and whenever numerical stability matters more than speed. Also the basis of the standard eigenvalue algorithm.

Cholesky whenever the matrix is symmetric and positive definite — covariance matrices, stiffness matrices, normal equations. Half the work, and it proves the property while it runs.

SVD when nothing else applies: it exists for every matrix, square or not, and handles rank deficiency gracefully. It is the most expensive and the most informative, and it is beyond what this page shows.

Sources and methodology

The factorisations and their numerical behaviour are standard; these are the references.

Method. LU runs on exact rationals and stays exact, so multiplying the factors back reconstructs the original with nothing to round. QR and Cholesky take square roots and are therefore decimal, and the page marks them as such rather than presenting all three alike. The QR uses modified Gram-Schmidt rather than the classical version: the two are identical on paper, but the classical one subtracts every projection from the original vector and accumulates error, losing orthogonality badly on nearly-dependent columns. The page reports how far QᵀQ actually falls from the identity. That engine is verified on every change against 104 hand-written assertions, including that L times U reconstructs the row-permuted original exactly across three hundred generated matrices, and that Cholesky succeeds on AᵀA for every invertible A — which it must, since that product is always positive definite. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Matrix InverseThe inverse in exact fractions, with the product A × A⁻¹ displayed — and it is exactly the identity, not the identity plus rounding noise.
DeterminantThe determinant of any square matrix up to 8×8, exact — by fraction-free elimination rather than the cofactor expansion that becomes unusable past 4×4.
Row Echelon FormReduced row echelon form with every step shown, plus rank, nullity, pivot columns and a null space basis — all exact, because rank is a question about zeros.
EigenvalueEigenvalues and the characteristic polynomial up to 6×6 — the polynomial exact and the roots decimal, because roots of a polynomial are generally irrational.
System of EquationsSolve linear systems in up to six unknowns with exact fractions — row operations, the matrix form, Cramer’s rule, and the parametric family when there is no single answer.
Linear RegressionThe least-squares line with r and r² — and the regression of x on y beside it, because those are two different lines rather than one line rearranged.

More in Math, or browse all calculators.

Read the guide

Factoring once and substituting is why numerical libraries advise against inverting a matrix — the Matrix Inverse Calculator sets out that argument.

Educational use disclaimer

This is an educational tool. LU is exact on rational inputs; QR and Cholesky involve square roots and are therefore decimal.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the decomposition page splitting the three methods by exactness and saying so: LU needs only arithmetic and stays exact on rationals, while QR and Cholesky take square roots and are decimal.
  2. Uses modified rather than classical Gram-Schmidt for the QR, since the two are identical on paper and the classical one loses orthogonality badly on nearly-dependent columns — and reports how far QᵀQ actually falls from the identity.
  3. Treats a Cholesky failure as a result rather than an error: reaching a non-positive value under the square root is exactly what 'not positive definite' means, which makes attempting one the cheapest test for that property.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.