How this calculation works
Decompose a complete matrix into low rank and entrywise sparse parts with the convex principal component pursuit objective.
minimize ||L||_* + λ||S||₁ subject to D=L+S.A worked example
The default matrix is all ones except its middle entry is five. The illustrative decomposition L=all ones and S with only S₂₂=4 reconstructs D exactly; the solver must optimize and certify its objective rather than assume this split.
Good to know
Complete real matrices 3–30 rows and columns, positive supplied lambda. Bounded convex numerical optimization with equality, stationarity and objective diagnostics. No noisy tolerance model, missing values, universal rank recovery or exact support identification guarantee.
Reference: Candès, Li, Ma and Wright: principal component pursuit (opens in a new tab) ↗
Separate repeated structure from sparse corruption
Ordinary principal components seek a low-rank approximation under a squared-error criterion. A few large corrupted entries can dominate that criterion. Principal component pursuit instead represents the data matrix as the exact sum of a low-rank candidate L and an entrywise sparse candidate S, with separate penalties controlling their complexity.
Low rank means the rows and columns share a small-dimensional linear structure. Sparse means many individual entries are zero. These properties are different: a matrix supported on one full row is sparse by entry count but can also have low rank. The optimization cannot universally identify a unique physical cause without conditions on how the two components overlap.
Compare this with the Principal component analysis calculator from a data matrix. Split an entire matrix into a low-rank component and sparse corruption using principal component pursuit, rather than rotate centered data to maximize explained variance.
Enter a complete matrix and choose the penalty
Provide three to thirty rows and columns of finite real values. All rows must have the same length, and every position must be observed. Enter lambda explicitly so that the tradeoff between nuclear norm and sparse absolute magnitude is visible. A positive value is required; an absent entry is not treated as an observed zero.
The equality model assigns every entered value to L plus S. It does not include an independent noise residual. If measurements contain widespread small noise, forcing exact equality can allocate that noise to either component. A noisy robust-PCA formulation uses a different constraint or loss and should not be silently substituted while retaining an exact-decomposition description.
Understand the two convex penalties
The nuclear norm is the sum of singular values and acts as a convex surrogate for matrix rank. The entrywise L1 norm is the sum of absolute matrix entries and encourages sparse corrections. Lambda weights the second term relative to the first. Increasing lambda makes a large sparse correction more expensive in the optimization objective.
Neither penalty directly fixes a desired rank or number of nonzero entries. Those properties emerge from the optimum and from the numerical thresholds used to summarize it. The output should keep the actual singular values and component matrices available so that a reported rank is not mistaken for an exact algebraic statement about rounded floating-point values.
Check feasibility and optimality separately
The reconstruction residual measures how closely L plus S reproduces D. A small residual confirms approximate feasibility, but many decompositions are feasible. It does not establish that the chosen pair minimizes the objective. Stationarity, dual feasibility and objective-gap diagnostics provide complementary evidence that the bounded numerical iteration solved the intended convex problem.
A stopping rule based only on successive iterates can stop when progress is slow, even if the answer remains inaccurate. This page treats unresolved diagnostics as an unresolved solve. It does not relabel the last iterate as an exact optimum merely because the components look visually plausible. The convex model helps, but finite-precision arithmetic still requires checked stopping conditions.
Inspect the structured default matrix
Every default entry is one except the central entry, which is five. One natural candidate uses the all-ones rank-one matrix for L and a single correction of four in the center for S. Adding those matrices reconstructs the displayed input exactly. This is a useful reconstruction example, not a proof that this particular split wins for every lambda.
At the supplied penalty, the solver compares the nuclear-norm cost of changes in L with the weighted absolute cost of changes in S. Different penalties can move a feature between components. Always read the calculated objective and diagnostics alongside the matrices. A human expectation that one entry is an outlier does not override the optimization model.
Scaling and transposition reveal useful invariances
Transposing D transposes any candidate components and leaves both objective norms unchanged. Multiplying all entries by a common nonzero scale multiplies the objective by the scale’s absolute value and rescales the component values. These are consistency checks for the same lambda; changing lambda at the same time changes the model.
Adding a constant to every entry is not an invariance of the optimization objective, even though a constant matrix has low rank. Centering data is therefore a modeling decision. State whether the matrix contains raw measurements or centered measurements before comparing decompositions, and do not automatically interpret a recovered constant component as background in every application.
Avoid a stronger recovery claim than the model supports
The foundational recovery theory assumes suitable incoherence and sparsity conditions. An arbitrary small matrix need not satisfy them, and this browser calculation does not verify a universal recovery theorem for the supplied input. A converged numerical optimizer solves the stated penalty model; it does not prove that its sparse component equals every real-world corruption.
Use the page to explore an explicit low-rank-plus-sparse decomposition with transparent limits. Inspect both components, the reconstruction and the objective checks. For ordinary variance-explained PCA, use the corresponding covariance or singular-value tool. Keeping approximation, decomposition and physical interpretation separate prevents a clean-looking split from being presented as a guaranteed denoising or anomaly-detection result.
A few questions, answered
Is this the same as ordinary PCA?
No. It solves a nuclear-norm plus entrywise-L1 decomposition with D=L+S, rather than a squared-error rank approximation.
Does a tiny reconstruction residual prove optimality?
No. It checks feasibility; stationarity and objective diagnostics are also needed.
Why can lambda change the recovered rank?
It changes the relative cost of sparse corrections and low-rank structure in the objective.
Can I enter missing values?
No. This page’s model requires a complete observed matrix.