Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab Subspace Angles

Subject: Matlab Subspace Angles

From: Robert Nicholls

Date: 9 Jun, 2010 21:26:05

Message: 1 of 2

Firstly, I may be off-base but here goes. I believe that if I have a 4 dimensional space (spanned by 4 columns of a 4x4 matrix) then I may have two subspaces defined by the first two columns and the last two columns of the matrix. The columns may either span the subspaces or define two null spaces. The angle between the two null spaces defined by columns 1:2 and 3:4 should be a two dimensional vector, ie. there are two angles that satisfy the minimization criterion. The dimension of the angle vector will be defined by the dimension of the subspaces for other sizes of matrix. There are a number of references but Kendall, M.G "A Course in the Geometry of n Dimensions" seems to be straight forward in the definition. However, the MATLAB subspace function returns a single angle regardless of the dimensions of the subspaces.

My question then is: What is the single value being returned by the "subspace" function and should it be multidimensional depending on the dimensions of the subspaces (or adjunct spaces)?

Thank,
Bob

Subject: Matlab Subspace Angles

From: Roger Stafford

Date: 11 Jun, 2010 07:50:08

Message: 2 of 2

"Robert Nicholls" <robert.nicholls@comcast.net> wrote in message <hup0td$qr8$1@fred.mathworks.com>...
> Firstly, I may be off-base but here goes. I believe that if I have a 4 dimensional space (spanned by 4 columns of a 4x4 matrix) then I may have two subspaces defined by the first two columns and the last two columns of the matrix. The columns may either span the subspaces or define two null spaces. The angle between the two null spaces defined by columns 1:2 and 3:4 should be a two dimensional vector, ie. there are two angles that satisfy the minimization criterion. The dimension of the angle vector will be defined by the dimension of the subspaces for other sizes of matrix. There are a number of references but Kendall, M.G "A Course in the Geometry of n Dimensions" seems to be straight forward in the definition. However, the MATLAB subspace function returns a single angle regardless of the dimensions of the subspaces.
>
> My question then is: What is the single value being returned by the "subspace" function and should it be multidimensional depending on the dimensions of the subspaces (or adjunct spaces)?
>
> Thank,
> Bob
- - - - - - - - -
  Apparently matlab's 'subspace' produces only the largest of the principal angles between subspaces. To get them all (in your case, both of them) you can use the function 'subspacea' on the file exchange written by Andrew Knyazev. The author takes special pains to handle small angles accurately. It is located at:

 http://www.mathworks.com/matlabcentral/fileexchange/55-subspacea-m

  Note: In 'subspacea' for your purposes you would probably want to use only the first two arguments, which makes the third argument, A, default to the identity matrix. This would give you the usual Euclidean scalar (dot)product.

  Or you could just do the following which is similar to the algorithm in matlab's 'subspace' but returns all the principal angles. However it does suffer accuracy problems for very small angles. The use of 'min' here avoids producing complex-valued angles for 'acos' arguments slightly above one due to roundoff error, but is symptomatic of the difficulties with small angles.

A = orth(A);
B = orth(B);
s = svd(A'*B);
a = acos(min(s,1));

  Note to Mathworks people: Even in matlab's latest documentation for 'subspace' the false statement is still being made, "If A and B are column vectors of unit length, this is the same as acos(A'*B)." It should read

 acos(abs(A'*B))

because vectors A and B could easily have a negative scalar product, but none of the principal angles should ever exceed pi/2. Fortunately 'subspace' itself does not make that mistake.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us