# lscov

Least-squares solution in presence of known covariance

## Syntax

## Description

specifies the algorithm for solving the linear system. By default,
`x`

= lscov(`A`

,`b`

,`C`

,`alg`

)`lscov`

uses the Cholesky decomposition of `C`

to
compute `x`

. Specify `alg`

as
`"orth"`

to use an orthogonal decomposition of `C`

. If
`C`

is not invertible, `lscov`

uses an orthogonal
decomposition regardless of the value of `alg`

.

## Examples

## Input Arguments

## Output Arguments

## Algorithms

When `m`

-by-`n`

matrix `A`

and
`m`

-by-`m`

matrix `C`

are full rank in
a generalized least-squares problem, these standard formulas represent the outputs of
`lscov`

when `m`

is greater than or equal to
`n`

.

x = inv(A'*inv(C)*A)*A'*inv(C)*b mse = (b - A*x)'*inv(C)*(b - A*x)./(m-n) S = inv(A'*inv(C)*A)*mse stdx = sqrt(diag(S))

When `m`

is less than `n`

, the mean squared error is 0.

For weighted least squares, the standard formulas apply when substituting
`diag(1./w)`

for `C`

. For ordinary least squares,
substitute the identity matrix for `C`

.

The `lscov`

function uses methods that are faster and more stable than
the standard formulas, and are applicable to rank-deficient cases. For instance,
`lscov`

computes the Cholesky decomposition `C = R'*R`

and then solves the least-squares problem `(R'\A)*x = (R'\b)`

instead, using
the same algorithm that is used in `mldivide`

for `A\b`

to
solve a least-squares problem.

## References

[1] Paige, Christopher C. "Computer
Solution and Perturbation Analysis of Generalized Linear Least Squares Problems."
*Mathematics of Computation* 33, no. 145 (1979): 171–83. https://doi.org/10.2307/2006034.

[2] Golub, Gene H., and Charles F. Van
Loan. *Matrix Computations*. Baltimore, MD: Johns Hopkins University
Press, 1996.

[3] Goodall, Colin R. "Computation
using the QR decomposition." *Handbook of Statistics* 9 (1993): 467–508.
https://doi.org/10.1016/S0169-7161(05)80137-3.

[4] Strang, Gilbert.
*Introduction to Applied Mathematics*. Wellesley, MA:
Wellesley-Cambridge Press, 1986.

## Extended Capabilities

## Version History

**Introduced before R2006a**