Rein
Rein

Reputation: 137

Vectorizing matrix multiplication in matlab

I would like to transform the matrix product AX-XB into vector form.

That is Cx where x=vec(X)

Yet I found the last term (XB) is very difficult to vectorize, it would be very sparsy.

Any effective way to do this?

Please see this link for the transformation to vector form

Upvotes: 1

Views: 1173

Answers (1)

Jan
Jan

Reputation: 5162

If you don't need C explicitly - like for iterative solvers - you can define an abstract linear operator that returns the vectorized product C*x. Not sure, if there is such a particular function in Matlab as SciPy's LinearOperator, but an anonymous function should do as well:

C_x = @(X) vec(A*X-X*B);

where vec 'vectorises' the matrix, e.g. via X(:) as @Jonas has pointed out.

EDIT: A closed form was suggested by @Eitan T below!!

See Matlab Help for how to use anonymous functions and function handles.

The formula for the explicit C is given here.

Upvotes: 1

Related Questions