Least Squares Calculator
Linear least squares for a small real matrix, square or rectangular. Full column rank uses QR; otherwise SVD. Same engine as Linear System. Not Statistics regression. Runs locally.
Enter values to calculate.
Trust summary CVP VERIFIED · CVP protocol 1.0.0-proposed · Core assurance · all published modes
- Input interpretation
- Enter values to calculate.
- Result
- —
- Verified scope
- all published modes
- Assurance
- Core
- Declared partition coverage
- PASS · 19/19 declared partitions (solve, det, inverse, multiply, transpose, rank, eigen, lu, chol, qr, svd, lstsq, rref, condition, nullspace, columnspace, rowspace, leftnullspace, invalid-domain) · Matrix
- Known limitations
- Core CVP does not include live graph, viewport, or pointer interaction.
- Model
- min ‖Ax − b‖₂ for a small real matrix (square or rectangular, m,n ∈ [2,4]).
- Scope
- Real matrices
- Verification
- Engine tested · Specification checked · v1.14.0 · CVP VERIFIED · CVP protocol 1.0.0-proposed · Core assurance · all published modes· View Manifest · CVP overview · Specification
- Versions
- Calculation 1.14.0 · CVP protocol 1.0.0-proposed · Evidence 2026-09-22.la-hardening-lu-svd
- Verification revision
- 2026-09-22.la-hardening-lu-svd · 7/7 property · digest 7307c47e0dc1
- Legacy regression
- 58/58 tests · Production surface contract 5/5
- Trust layers
- Verification VERIFIED · Production CURRENT · Overall CVP state: VERIFIED under CVP 1.0.0-proposed
- Reference
- O1 model · O2 expected_values · O2 numerical_behavior
- Interfaces
- PASS · UI (SSR) / REST / MCP
- Supplemental domain review
- Not performed
- Named expert review
- Not performed
- CVP suite
- 24/24 golden · 8/8 CVP boundary · 14/14 invalid · 7/7 property · 9/9 cross-interface · 2/2 cross-calculator · 5/5 CVP contract · Manifest
- Specification basis
- ISO 80000-2:2019 Quantities and units — Mathematics
- Evidence
- 29 legacy golden · 6 legacy boundary · legacy regression suite · 24/24 oracle-backed golden · 14/14 invalid · Artifact integrity PASS
- Semantic contract
- PASS
Full verification
Formulas
Core equations used by this calculator.
How to use
Enter A and b
Choose 2×2, 3×3, 3×2 (overdetermined), or 2×3 (min-norm). Same fields as Linear System. Larger composition lives at /workspace/matrix.
Read x and residual₂
method is qr or svd_pinv. residual_2 is ‖Ax − b‖₂. Rank-deficient and underdetermined return the min-norm solution.
Example calculations
Common configurations with formula and result.
Full rank square
2x + y = 5, x + y = 3
Overdetermined 3×2
[[1,1],[1,2],[1,3]] b=[1,2,2]
Rank 1
[[1,2],[2,4]] b=[1,0]
Least Squares calculator specification
Version 1.14.0 · Engine tested
- Engine tested 58/58 tests · Production surface contract 5/5
- Named expert review Not performed
- Calculation version 1.14.0
- Definition
- x minimizes ‖Ax − b‖₂. Full column rank (including overdetermined m×n, m≥n) uses Householder QR; rank-deficient or underdetermined uses the SVD pseudoinverse. This page is mode=lstsq on math.linear_algebra. Not a second engine. Not y=a+bx regression.
- What it calculates
- min ‖Ax − b‖₂ for a small real matrix (square or rectangular, m,n ∈ [2,4]).
- Inputs
- order or rows+cols
- a11…
- b1…
- Outputs
- x
- y
- z
- residual_2
- rank_numeric
- method
- status
- rows
- cols
- Formula
min ‖Ax − b‖₂- Assumptions
- Real matrices
- m,n ∈ [2,4]
- Planar ℝ² figure when 2×2; other shapes omit it
- Float64
- Not a CAS
- Not Statistics regression
- Units
- dimensionless
- Boundary conditions
- unknown mode (including jordan-form) → INVALID_MODE
- rows or cols outside 2–4 → INVALID_INPUT
- Example
- [[1,1],[1,2],[1,3]] b=[1,2,2] → x=2/3, y=1/2
- Validation cases
3 published on this page · 58/58 tests · Production surface contract 5/5 · View evidence
- order=2 a11=2 a12=1 a21=1 a22=1 b1=5 b2=3 → x=2 y=1 residual_2≈0
- rows=3 cols=2 a11=1 a12=1 a21=1 a22=2 a31=1 a32=3 b1=1 b2=2 b3=2 → x=2/3 y=1/2 method=qr
- mode=jordan-form order=2 a11=1 a12=0 a21=0 a22=1 → INVALID_MODE
- Specification basis
- ISO 80000-2:2019 Quantities and units — Mathematics
- Calculation version
- 1.14.0
Related tools
Other calculators in this family: Cholesky Factorization Calculator, Column Space Calculator, Condition Number Calculator, Left Nullspace Calculator, Linear System Calculator, LU Factorization Calculator, Matrix Determinant Calculator, Matrix Eigenvalues Calculator . Explore all Linear Algebra.
Frequently asked questions
Key distinctions behind the calculation.
Is this a second linear-algebra engine?
No. It is mode=lstsq on math.linear_algebra, the same engine as /calc/math/linear-system and /workspace/matrix.
Is this Statistics linear regression?
No. This is Ax ≈ b for a small matrix. A slope-intercept fit of a point cloud is a Statistics product, not this page.
Does rectangular mean a new Capability?
No. rows and cols grow this same math.linear_algebra contract. Solve / det / inverse / LU / Cholesky stay square. QR and SVD are sibling discovery URLs on this same engine and also accept rectangular A.