Advertisement
Advertisement
LINEAR ALGEBRA

SVD Calculator — singular value decomposition of any real matrix

Enter a matrix and get its singular values, the orthogonal factors U and V, the numerical rank and the condition number, with the reconstruction error printed so the answer verifies itself.

One row per line, entries separated by spaces, commas or tabs. Every row must be the same length. Up to 8 rows by 8 columns. Rectangular matrices are fine in either orientation.
Arithmetic is always full double precision; this controls the display only.
A singular value counts towards the rank if it exceeds this multiplier times the default tolerance, which is the largest singular value multiplied by the larger dimension and by machine epsilon.
Largest singular value
 
Matrix size
Numerical rank
Condition number
Reconstruction error
Singular values:
U:
V:
Working:
Tip: the reconstruction error is the largest entry-by-entry difference between U times sigma times V transpose and the matrix you entered. It should be at the level of floating-point rounding. The bar display shows each singular value as a share of the largest, which is where a rank drop becomes obvious.
Advertisement

The SVD calculator above factors any real matrix A into three pieces: an orthogonal U, a diagonal matrix of non-negative singular values, and an orthogonal V transpose. Every real matrix has such a factorisation, square or not, singular or not, which is what makes the singular value decomposition the most generally useful tool in matrix analysis. The page returns the singular values, both orthogonal factors, the numerical rank, the condition number and a verification of the product.

Arb Digital publishes it because so many practical questions reduce to reading a list of singular values. How close is this matrix to singular? How many dimensions does this data really occupy? What is the best low-rank approximation? Each is answered directly by the numbers this page returns. Where the QR decomposition calculator gives you an orthonormal basis quickly, the SVD gives you the one aligned with the directions of greatest stretch, and it is the only decomposition that reveals rank reliably. The eigenvalue calculator handles the related but distinct spectral question for square matrices.

What This SVD Calculator Does

It computes the compact singular value decomposition of a matrix up to eight by eight in either orientation. U has as many rows as A and as many columns as there are singular values; V has as many rows as A has columns. The singular values are returned in descending order, which is the universal convention and the one that makes the low-rank approximation results work.

Four summary numbers come back. The largest singular value is the spectral norm of the matrix, the largest factor by which A can stretch a unit vector. The numerical rank counts the singular values above a tolerance. The condition number is the largest singular value divided by the smallest, which measures how much a relative error in the input can be amplified in the solution of a linear system. The reconstruction error is the verification: it should be at rounding level, and it is printed so you can confirm that rather than assume it.

The bar display underneath shows each singular value as a percentage of the largest. On a full-rank well-conditioned matrix the bars are all substantial. On a rank-deficient one the last bar collapses to nothing, and that visual is often clearer than the number itself.

How to Use It

  1. Type the matrix one row per line, entries separated by spaces, commas or tabs. Rows must all have the same length. Tall, wide and square matrices are all accepted.
  2. Read the singular values first. They are the substance of the decomposition; U and V are the directions those stretches act along.
  3. Check the condition number. A value near one means a well-behaved matrix. A value of ten to the sixteenth means the matrix is numerically singular to double precision.
  4. Adjust the rank tolerance if you have a reason to. The default is the standard convention, but rank in floating point is a judgement rather than a fact, and this input lets you make that judgement explicit.
  5. Confirm the reconstruction error is tiny before you rely on the factors, and use the example buttons to see how a rank-deficient and an ill-conditioned matrix differ.

The Formula and How It Is Calculated

The decomposition is A = U Σ Vᵀ, where U and V have orthonormal columns and Σ is diagonal with non-negative entries. Equivalently, the columns of V are the eigenvectors of AᵀA, the columns of U are the eigenvectors of AAᵀ, and the singular values are the non-negative square roots of the shared eigenvalues of those two products. The full definition is set out in the MathWorld entry on the singular value decomposition.

That eigenvector characterisation is how the SVD is usually taught and is exactly how it should not be computed. Forming AᵀA squares the condition number and destroys the small singular values, which are frequently the ones you care about. This page instead uses the one-sided Jacobi method, which repeatedly rotates pairs of columns of A until they are mutually orthogonal. When the process converges, the column norms are the singular values and the normalised columns are U, with the accumulated rotations forming V. The product AᵀA is never formed at any point.

Worked example, using the two-by-two matrix loaded by default: rows (3, 0) and (4, 5). Its transpose times itself is the matrix with rows (25, 20) and (20, 25), whose eigenvalues are 45 and 5. The singular values are therefore the square root of 45, which is 6.708204, and the square root of 5, which is 2.236068. Their product is the square root of 225, which is 15. The determinant of the original matrix is three times five minus zero times four, which is also 15. The two agree exactly, as they must, because the absolute determinant of any square matrix is the product of its singular values. The condition number is 6.708204 divided by 2.236068, which is exactly 3.

Advertisement

Why the SVD Is the Only Reliable Rank Test

Rank is defined as the number of linearly independent columns, which in exact arithmetic is a clean integer. In floating point it is not, because a column that is exactly dependent in theory will be dependent to within rounding error in practice, and no exact test can distinguish that from a column that is genuinely almost dependent. Every numerical rank is therefore a decision about a tolerance.

What makes the SVD the right basis for that decision is a theorem: the smallest singular value is exactly the distance, measured in the spectral norm, from A to the nearest matrix of lower rank. So a smallest singular value of ten to the minus twelve does not merely suggest near-dependence, it tells you precisely how large a perturbation would make the matrix genuinely rank deficient. No other quantity available from a matrix carries that guarantee. A determinant near zero does not, because determinants scale like the nth power of the entries and a well-conditioned matrix of small entries has a tiny determinant. The diagonal of R from a QR factorisation does not either, because it can hide rank deficiency entirely.

This is why the matrix rank calculator, which uses row reduction, and this page can disagree on a marginal matrix. Row reduction gives the exact answer to the arithmetic it performed; the SVD gives you the distance to the boundary and lets you choose. On clean integer data they will agree.

Low-Rank Approximation and Where It Is Used

The Eckart-Young theorem says that if you keep only the largest k singular values and their matching columns of U and V and discard the rest, the result is the closest rank-k matrix to A in both the spectral and Frobenius norms. Nothing else is closer. That single fact is the mathematical content behind an enormous amount of applied work.

Principal component analysis is the SVD of a mean-centred data matrix, with the singular values squared and divided by the sample size giving the variance along each principal direction. Image compression by SVD truncation follows the same argument. Latent semantic analysis in text retrieval was built on it. Recommender systems that factor a user-item matrix are computing a low-rank approximation, usually a regularised one. In every case the ratio of the discarded singular values to the retained ones bounds the error, so the bar display on this page is a direct picture of how much information a truncation would cost.

Reading the Condition Number Honestly

The condition number is the ratio of the largest singular value to the smallest, and it bounds how much the relative error in the solution of a linear system can exceed the relative error in the data. A rough rule of thumb is that you lose about as many decimal digits of accuracy as the base-ten logarithm of the condition number. Double precision carries roughly sixteen digits, so a condition number of ten to the tenth leaves about six trustworthy digits.

Two cautions. It is a worst-case bound, not a prediction: many badly conditioned systems are solved perfectly well because the right-hand side happens to avoid the sensitive direction. And it depends on scaling. Multiplying one row of a matrix by a thousand changes the condition number without changing the mathematical problem, which is why the condition number of a badly scaled matrix says more about the units than the matrix. Rescale the rows to comparable magnitude before reading it as a difficulty measure. The matrix norm calculator covers the norms this ratio is built from.

Numerical Caveats You Should Know

Singular values are always well determined: a small change in A produces a change in each singular value no larger in absolute terms, so they can be computed to high absolute accuracy regardless of conditioning. The singular vectors are not so well behaved. When two singular values are close together, the individual vectors in U and V are extremely sensitive, because the two-dimensional subspace they span is well determined but the choice of basis within it is not. Repeated singular values make the individual vectors genuinely non-unique, and any answer within the subspace is correct.

Signs are never unique. Negating a column of U and the matching column of V leaves the product unchanged, so two correct implementations can differ by sign patterns. Do not treat a sign disagreement with another tool as an error. And this page uses the compact form: the columns of U beyond the number of singular values, which span the left null space, are not returned. The LAPACK users' guide section on the singular value decomposition sets out the full and reduced conventions in detail.

Finally, one-sided Jacobi is accurate but not fast. It is an excellent choice for the small matrices this page handles and a poor one for anything large, where the bidiagonalisation-based methods in LAPACK are the standard. If your matrix is bigger than eight by eight, use a library rather than a web page.

Need analysis that shows its own working?

Arb Digital builds measurement and reporting systems where every number can be traced back to the arithmetic that produced it.

Browse All Free Tools Talk To Our Team

Common Mistakes to Avoid

  • Confusing singular values with eigenvalues — they coincide only for symmetric positive semi-definite matrices. Singular values are always real and non-negative; eigenvalues can be negative or complex.
  • Computing the SVD from A transpose A — it squares the condition number and annihilates the small singular values, which are usually the interesting ones.
  • Treating a sign difference as a bug — U and V columns are determined only up to a shared sign, so implementations legitimately disagree.
  • Reading the condition number without checking the scaling — rescaling a single row changes it dramatically while changing nothing about the underlying problem.
  • Trusting individual singular vectors when values are close — the subspace is stable, the basis within it is not, and a tiny perturbation can rotate the vectors completely.

Related Free Tools From Arb Digital

Get an orthonormal basis faster with the QR decomposition calculator, build the Moore-Penrose inverse from these factors with the pseudoinverse calculator, find eigenvalues of a square matrix with the eigenvalue calculator, check rank by row reduction with the matrix rank calculator, or invert a square matrix with the matrix inverse calculator. The full free online tools hub lists every linear algebra tool we publish.

Frequently Asked Questions

Does every matrix have a singular value decomposition?

Yes. Every real matrix of any shape has one, including singular and rectangular matrices. That universality is what separates the SVD from eigendecomposition, which many square matrices do not admit.

How do singular values differ from eigenvalues?

Singular values are the non-negative square roots of the eigenvalues of A transpose times A. For a symmetric positive semi-definite matrix they equal the eigenvalues; otherwise they are different quantities entirely.

Why not compute the SVD from A transpose A directly?

Forming that product squares the condition number, so singular values smaller than the square root of machine epsilon relative to the largest are lost completely. This page uses one-sided Jacobi and never forms the product.

What does the reconstruction error tell me?

It is the largest entry-by-entry difference between U times sigma times V transpose and your original matrix. At rounding level it confirms the factorisation; anything larger means the algorithm has not converged.

Why is the SVD the right way to determine rank?

Because the smallest singular value is exactly the distance to the nearest matrix of lower rank. That gives the tolerance decision a precise meaning that determinants and row reduction cannot provide.

Are U and V unique?

Only up to signs, and not even that when singular values repeat. A repeated value makes the corresponding subspace unique but leaves the choice of basis within it free, so many correct answers exist.

What is the relationship to principal component analysis?

PCA on a mean-centred data matrix is the SVD of that matrix. The right singular vectors are the principal directions and the squared singular values, divided by the sample size, are the variances along them.

Is the product of the singular values the determinant?

For a square matrix the product equals the absolute value of the determinant. The sign is lost, because singular values are non-negative by definition and the orientation information sits in U and V.

This page explains a numerical linear algebra method for educational purposes. All arithmetic is double precision, and a matrix whose condition number approaches ten to the sixteenth is numerically singular at that precision regardless of what the factors appear to show.

Advertisement
Advertisement

Take it further