Least Squares Calculator
Linear least squares for a small real square system. Full rank uses QR; rank-deficient uses SVD. Same engine as Linear System. Not Statistics regression. Runs locally.
Trust summary Engine tested · Specification checked · 44/44 tests · Production surface contract 3/3 · v1.10.0
- Input interpretation
- Enter values to calculate.
- Result
- —
- Model
- min ‖Ax − b‖₂ for a small real square matrix (order 2–4).
- Scope
- Real square matrices
- Verification
- Engine tested · 44/44 tests · Production surface contract 3/3 · Specification checked · v1.10.0
- Named expert review
- Optional · Not performed
- Specification basis
- ISO 80000-2:2019 Quantities and units — Mathematics
- Evidence
- 23 golden · 2 boundary · 19 property · Production surface contract 3/3 · Artifact integrity PASS
- Production
- Embedded snapshot: STALE · Last attested schema matched 1.10.0 snapshot / local build · Semantic contract ✓ · Last attestation PASS · current evidence changed · re-attestation required · Public/cache ✓ · Origin ✓ · Live production status STALE (1 capability; 163 remain CURRENT) @ 2026-09-19T00:00:17.039Z
- Semantic contract
- PASS
Formulas
Core equations used by this calculator.
How to use
Enter A and b
2×2 or 3×3. 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 returns the min-norm solution.
Example calculations
Common configurations with formula and result.
Full rank
2x + y = 5, x + y = 3
Rank 1
[[1,2],[2,4]] b=[1,0]
Least Squares calculator specification
Version 1.10.0 · Engine tested
- Engine tested 44/44 tests · Production surface contract 3/3
- Named expert review Not performed
- Calculation version 1.10.0
- Definition
- x minimizes ‖Ax − b‖₂. Full column rank uses Householder QR; rank-deficient 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 square matrix (order 2–4).
- Inputs
- order
- a11…
- b1…
- Outputs
- x
- y
- z
- residual_2
- rank_numeric
- method
- status
- Formula
min ‖Ax − b‖₂- Assumptions
- Real square matrices
- Order ≤ 4
- Float64
- Not a CAS
- Not Statistics regression / rectangular overdetermined
- Units
- dimensionless
- Boundary conditions
- unknown mode (including jordan-form) → INVALID_MODE
- Example
- 2x+y=5, x+y=3 → x=2, y=1
- Validation cases
2 published on this page · 44/44 tests · Production surface contract 3/3 · View evidence
- order=2 a11=2 a12=1 a21=1 a22=1 b1=5 b2=3 → x=2 y=1 residual_2≈0
- 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.10.0
Related tools
Other calculators in this family: Column Space Calculator, Condition Number Calculator, Left Nullspace Calculator, Linear Equation Calculator, Linear System Calculator, LU Factorization Calculator, Matrix Determinant Calculator, Matrix Eigenvalues Calculator . Explore all Algebra & Equations.
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.