Skip to contents

Mirrors the C# QRDecomposition::Solve overloads (vector and matrix right-hand sides). a need not be square: an overdetermined system is solved in the least-squares sense; an underdetermined system leaves the trailing ncol(a) - min(nrow(a), ncol(a)) unknowns at zero (matching QRDecomposition.Solve's own truncated back-substitution, which only ever fills indices below min(m, n)).

Usage

qr_solve(a, b)

Arguments

a

a numeric matrix, M x N.

b

a numeric vector of length M, or a numeric matrix with M rows.

Value

a numeric vector of length N when b is a vector, or an N x ncol(b) matrix when b is a matrix.

Examples

a <- matrix(c(1, 2, 3, 0, 1, 4, 5, 6, 0), nrow = 3, byrow = TRUE)
qr_solve(a, c(1, 2, 3))
#> [1]  27 -22   6