home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / DATAFUN.DI$ / SUBSPACE.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.0 KB  |  30 lines

  1. function theta = subspace(a,b)
  2. %SUBSPACE Angle between two subspaces.
  3. %    SUBSPACE(A,B) finds the angle between two subspaces specified
  4. %    by the columns of A and B.  If A and B are vectors of unit
  5. %    length, this is the same as ACOS(A'*B).
  6. %    If the angle is small, the two spaces are nearly linearly
  7. %    dependent.  In a physical experiment described by some
  8. %    observations A, and a second realization of the experiment
  9. %    described by B, SUBSPACE(A,B) gives a measure of the amount
  10. %    of new information afforded by the second experiment not
  11. %    associated with statistical errors of fluctuations.
  12.  
  13. %    L. Shure 11-03-88.
  14. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  15.  
  16. a = a.'; b = b.';
  17. [ma,na]=size(a);
  18. [mb,nb]=size(b);
  19. if ma ~= mb
  20.    error('Column dimensions of A and B must be the same.')
  21. end
  22. [qa,ra]=qr(a);
  23. [qb,rb]=qr(b);
  24. qa = qa(:,1:na);
  25. qb = qb(:,1:nb);
  26. g=qa'*qb;
  27. % the max singular value is the correct one to choose but should have magnitude
  28. % no more than 1.
  29. theta = acos(min(max(max(svd(g)),-1),1));
  30.