lscov
Least-squares solution with known covariance or weights.
Category: Mathematics > Linear Algebra
Syntax
x = lscov(A, b)
Ordinary least squares, the same as A\b for a full-rank A.
x = lscov(A, b, w)
Weighted least squares with the weight vector w.
x = lscov(A, b, V)
Generalized least squares for a covariance matrix V of the errors.
Description
Observations with different reliabilities should not count equally in a fit. A weight vector w is equivalent to a diagonal covariance V = diag(1./w). Giving the weight 4 to a point has the same effect as repeating that equation four times.
Input arguments
A- Design matrix with more rows than columns.
b- Observation vector.
w- Positive weights, one per observation; larger weights mean more reliable data.
V- Symmetric positive definite covariance matrix of the observation errors.
Output arguments
x- Coefficients minimizing the weighted squared residual
(b - A*x)' * inv(V) * (b - A*x).
Example
Ordinary and weighted line fit
A = [1 0; 1 1; 1 2];
b = [1; 2; 2];
x = lscov(A, b)
x2 = lscov(A, b, [1; 1; 4])
Output
x = 2×1
1.1667
0.5000
x2 = 2×1
1.1905
0.4286