heavy rocker dude
heavy rocker dude

Reputation: 2301

How to resolve this general Matlab matrix trick

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

Upvotes: 0

Views: 226

Answers (2)

abcd
abcd

Reputation: 42225

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.

Upvotes: 4

Amro
Amro

Reputation: 124563

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

Upvotes: 2

Related Questions