# atrix Products Expressed in Terms of Individual Operands (Scripts) 1.0

Average Rating
User Rating:
Visitors Rating:
My rating:

• Last update: 5 years ago
• Operating system: Linux, Mac OS X, Win All, BSD, Solaris
• Publisher: Matt J (15 other programs)
See full specifications

## atrix Products Expressed in Terms of Individual Operands (Scripts) Publisher's description

### This submission defines a class for representing products of matrices (or of any objects that know how to multiply)

This submission defines a class for representing products of matrices (or of any objects that know how to multiply) when it is more efficient to store and manipulate the matrices separately.

USAGE:

This creates an object P representing the matrix product A1*A2*...*An. Internally, however, the object stores/manipulates the matrices {A1,A2,...,An} individually, which can be more efficient memory-wise than when the product is fully evaluated. Furthermore, when evaluating a matrix-vector product A1*A2*...*An*x, it can be more efficient speed-wise to exploit associativity and compute the result using n successive products.

A simple example of this idea is the outer product u*v.' of column vectors u and v. Clearly, it is more efficient to multiply the outer product with a vector x as u*(v.'*x) than as (u*v.')*x. The following gives a demonstration of how the class exploits this.

u=rand(4000,1);
v=rand(4000,1);
x=rand(4000,1);

Pmat=u*v.';

tic
y1=Pmat*x;
z1=Pmat.'*y1;
toc;
%Elapsed time is 0.050854 seconds.

tic
y2=P*x;
z2=P.'*y2;
toc
%Elapsed time is 0.000457 seconds.

PercentError =100*norm([y2;z2]-[y1;z1])/norm([y1;z1]), %=7.8336e-014

>>whos Pmat P

Name Size Bytes Class Attributes

Pmat 4000x4000 128000000 double

Other situations where it can be better to store a matrix decomposed into a product would include, for example, when a large full matrix has a sparse decomposition.

Methods overloaded by the class include mtimes (*) ,tranpose (.') , ctranpose (') , det, and inv, which exploit the fact that these operations more or less distribute across matrix products. Also, some methods allow the object P to be manipulated as if it were the cell array {A1,...,An} that generated the object initially. For example, the expression A1=P{1} will extract the first operand of the product.

The ProdCascade class can be useful not just for holding products of matrices, but also of any operator objects that know how to multiply. Here is an example that uses my MatrixObj class
http://www.mathworks.com/matlabcentral/fileexchange/26611-on-the-fly-definition-of-custom-matrix-objects

to represent a frequency-domain filtering operation as a multiplication with ProdCascade object, P.

%%data
N=2^14;
x=rand(N,1);
LowPass=ones(N,1); LowPass(10:end-9)=0;

%%Make FFT operator
Q=MatrixObj;
Q.Ops.mtimes=@(Q,x) fft(x);
Q.Trans.mtimes=@(Q,x) ifft(x);

%%Make filtering operator, P*x should be equivalent to ifft(fft(x).*LowPass)

L=spdiags(LowPass,0,speye(N));

isequal( P*x,ifft(fft(x).*LowPass) )%=1

DISCAIMER: Error checking is never done to see whether the operators in a ProdCascade are compatible for successive multiplication.

#### System Requirements:

MATLAB 7.11 (2010b)
Program Release Status: New Release
Program Install Support: Install and Uninstall

#### atrix Products Expressed in Terms of Individual Operands (Scripts) Tags:

Click on a tag to find related softwares

## Most Popular

ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation