Learn R Programming

fastQR (version 1.1.4)

qrsolve: Solution of linear system of equations, via the QR decomposition.

Description

solves systems of equations \(Ax=b\), for \(A\in\mathbb{R}^{n\times p}\) and \(b\in\mathbb{R}^n\), via the QR decomposition.

Usage

qrsolve(A, b, type = NULL, nb = NULL)

Value

x a vector of dimension \(p\) that satisfies \(Ax=b\).

Arguments

A

an \((n\times p)\) full column rank matrix.

b

a vector of dimension \(n\).

type

either "QR" or "R". Specifies the type of decomposition to use: "QR" for the QR decomposition or "R" for the Cholesky factorization of \(A^\top A\). The default is "QR".

nb

number of blocks for the recursive block QR decomposition, default is NULL.

References

golub_van_loan.2013fastQR

bjorck.2015fastQR

bjorck.2024fastQR

bernardi_etal.2024fastQR

Examples

Run this code

## generate sample data
set.seed(1234)
n <- 10
p <- 4
A <- matrix(rnorm(n * p, 1), n, p)
b <- rnorm(n)

## solve the system of linear equations using qr
x1 <- fastQR::qrsolve(A = A, b = b)
x1

## solve the system of linear equations using rb qr
x2 <- fastQR::qrsolve(A = A, b = b, nb = 2)
x2

## check
round(x1 - solve(crossprod(A)) %*% crossprod(A, b), 5)
round(x2 - solve(crossprod(A)) %*% crossprod(A, b), 5)

Run the code above in your browser using DataLab