Learn R Programming

EigenR (version 1.2.3)

Eigen_lsSolve: Linear least-squares problems

Description

Solves a linear least-squares problem.

Usage

Eigen_lsSolve(A, b, method = "cod")

Arguments

A

a n*p matrix, real or complex

b

a vector of length n or a matrix with n rows, real or complex

method

the method used to solve the problem, either "svd" (based on the SVD decomposition) or "cod" (based on the complete orthogonal decomposition)

Value

The solution X of the least-squares problem AX ~= b (similar to lm.fit(A, b)$coefficients). This is a matrix if b is a matrix, or a vector if b is a vector.

Examples

Run this code
# NOT RUN {
set.seed(129)
n <- 7; p <- 2
A <- matrix(rnorm(n * p), n, p)
b <- rnorm(n)
lsfit <- Eigen_lsSolve(A, b)
b - A %*% lsfit # residuals
# }

Run the code above in your browser using DataLab