home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / MATFUN.DI$ / LSCOV.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1001 b   |  35 lines

  1. function x = lscov(A,b,V)
  2. %LSCOV    Least squares solution in the presence of known covariance.
  3. %    X = LSCOV(A,b,V) returns the vector X that minimizes
  4. %    (A*X-b)'*inv(V)*(A*X-b) for the case in which length(b) > length(X).
  5. %    This is the over-determined least squares problem with covariance V.
  6. %    The solution is found without needing to invert V which is a square
  7. %    symmetric matrix with dimensions equal to length(b).
  8. %
  9. %    The classical linear algebra solution to this problem is:
  10. %
  11. %        x = inv(A'*inv(V)*A)*A'*inv(V)*b
  12. %
  13. %    See also SLASH, NNLS, QR.
  14.  
  15. %    Reference:
  16. %        G. Strang, "Introduction to Applied Mathematics",
  17. %        Wellesley-Cambridge, p. 398, 1986.
  18. %    L. Shure 3-31-89
  19. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  20.  
  21. [m,n] = size(A);
  22. if m <= n
  23.     error('Problem must be over-determined.');
  24. end
  25. [q,r] = qr(A);
  26. efg = q'*V*q;
  27. e = efg(1:n,1:n);
  28. g = efg(n+1:m,n+1:m);
  29. cd = q'*b;
  30. f = efg(1:n,n+1:m);
  31. c = cd(1:n);
  32. d = cd(n+1:m);
  33. r = r(1:n,1:n);
  34. x = r\(c-f*(g\d));
  35.