0

Just a general Matlab matrix trick I am trying to understand? What does this line really mean logically?

S=X*X';

What does S accomplish if I transpose any generic matrix against itself? Thanks

heavy rocker dude
  • 2,271
  • 8
  • 33
  • 47

2 Answers2

4

If X is a general NxM matrix, then S=X*X' is the sum of the outer products of each of the columns of X with its transpose. In other words, writing X=[x1,x2,...,xM], S can be written as

S = ∑_i x_i * x_i'

The resulting matrix S is non-negative definite (i.e., eigenvalues are not negative).

If you consider each element in a column of X as a random variable (total N), and the different columns as M independent observations of the N dimensional random vector, then S is the NxN sample covariance matrix (differing by a constant normalization, depending on your conventions) of the rows. Similarly, S=X'*X gives you the MxM covariance matrix of the columns.


Now if you start restricting the generality and assign special properties to X, then you'll start seeing patterns emerge for the structure of S. For example, if X is square, has real entries and is orthogonal, then S=I, the identity matrix. If X is square, has complex entries and is a unitary matrix, then S is then again, the identity matrix.

Without knowing the exact circumstances in which this was used in your program, I would assume that they were calculating the covariance matrix.

abcd
  • 41,765
  • 7
  • 81
  • 98
  • I do believe identity matrix is correct for this context Thanks to all including Yoda – heavy rocker dude Nov 22 '11 at 02:06
  • @yoda - this is a well-written and helpful explanation, but I think in a couple of places you've got columns and rows confused. `S=X*X'` is the covariance matrix of the _rows_ of `X`; `X'*X` is the covariance matrix of the columns. Perhaps a quick edit could correct that. – Sam Roberts Nov 22 '11 at 14:47
2

Here is an example to show how this is related to the covariance matrix (as @yoda explained):

X = randn(5,3);                     %# 3 column-vectors each of dimension=5
X0 = bsxfun(@minus, X, mean(X,2));  %# zero-centered

C = (X0*X0') ./ (size(X0,2)-1)      %'# sample covariance matrix
CC = cov(X')                        %'# should return the same result
Community
  • 1
  • 1
Amro
  • 123,847
  • 25
  • 243
  • 454