HomeCalculatorsMathAlgebra & EquationsLeast Squares Calculator
Math calculator

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.

Instant result
Result

Enter values to calculate.

Inputs
Mode
Formula
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
Specification basis
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.

Objectivemin_x ‖Ax − b‖₂
Full rank QRA = QR, Rx = Qᵀb
Rank-deficient SVDx = V Σ⁺ Uᵀ b
iSquare matrices only, order ≤ 4. Reuses the QR and SVD modes on this same engine. Not rectangular overdetermined systems. Not a Statistics regression page. Float64.

How to use

1

Enter A and b

2×2 or 3×3. Same fields as Linear System. Larger composition lives at /workspace/matrix.

2

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

QR backsolve
x=2, y=1
ϟ

Rank 1

[[1,2],[2,4]] b=[1,0]

x = V Σ⁺ Uᵀ b
x=0.04, y=0.08

Least Squares calculator specification

Version 1.10.0 · Engine tested

Calculation status

Review policy · Evidence

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
}

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.