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:
Fast Matrix*Diagonal*Matrix operation

Subject: Fast Matrix*Diagonal*Matrix operation

From: Gongguo Tang

Date: 31 Jan, 2011 22:31:05

Message: 1 of 8

Hi there,

I have a code that computes Q'*D(t)*Q many times. Here Q is a fixed mxn matrix with m < n, while the diagonal matrix D depends on the iteration t.

Because I have so many iterations that the operation slows done the entire process.

I am wondering if there is any way to obtain Q'*D(t)*Q as fast as possible. Maybe from the result of Q'*Q or some kind of decomposition of Q'*Q?

Thanks in advance!

best,

Gongguo

Subject: Fast Matrix*Diagonal*Matrix operation

From: proecsm

Date: 1 Feb, 2011 01:35:04

Message: 2 of 8

"Gongguo Tang" wrote in message <ii7d79$lto$1@fred.mathworks.com>...
> Hi there,
>
> I have a code that computes Q'*D(t)*Q many times. Here Q is a fixed mxn matrix with m < n, while the diagonal matrix D depends on the iteration t.
>
> Because I have so many iterations that the operation slows done the entire process.
>
> I am wondering if there is any way to obtain Q'*D(t)*Q as fast as possible. Maybe from the result of Q'*Q or some kind of decomposition of Q'*Q?
>
> Thanks in advance!
>
> best,
>
> Gongguo

I think it is unlikely that there is a shortcut using Q'*Q or decomposition thereof. More likely is if you could a snippet of your code, someone could suggest a more efficient approach

Subject: Fast Matrix*Diagonal*Matrix operation

From: Rune Allnor

Date: 1 Feb, 2011 04:39:39

Message: 3 of 8

On Jan 31, 11:31 pm, "Gongguo Tang" <tanggong...@gmail.com> wrote:
> Hi there,
>
> I have a code that computes Q'*D(t)*Q many times. Here Q is a fixed mxn matrix with m < n, while the diagonal matrix D depends on the iteration t.
>
> Because I have so many iterations that the operation slows done the entire process.
>
> I am wondering if there is any way to obtain Q'*D(t)*Q as fast as possible. Maybe from the result of Q'*Q or some kind of decomposition of Q'*Q?

Sounds like you might want to have a look at
how the Householder transform helps speed up
the computation of eigenvalues of symmetric
matrices.

Check out the appropriate chapters of

Golub & van Loan: "Matrix Computations" (1996)

Rune

Subject: Fast Matrix*Diagonal*Matrix operation

From: Bruno Luong

Date: 1 Feb, 2011 07:18:03

Message: 4 of 8

"Gongguo Tang" wrote in message <ii7d79$lto$1@fred.mathworks.com>...

>
> I am wondering if there is any way to obtain Q'*D(t)*Q as fast as possible. Maybe from the result of Q'*Q or some kind of decomposition of Q'*Q?
>

I'm pretty sure the answer is: no, it's not possible.

Bruno

Subject: Fast Matrix*Diagonal*Matrix operation

From: Gongguo Tang

Date: 3 Feb, 2011 20:57:03

Message: 5 of 8

Hi proecsm,

Thanks for your reply. The first two lines below are my codes for computing Q'*D(t)*Q, where D(t) = diag(sig3) and sig3 changes every iteration. I still need several other lines to implement additional computations.

I would appreciate if anyone could speed up the code.

----------------
Qtmp = bsxfun(@times,Q.',sig3');
H = Qtmp*Q;
p = sqrt(-eta)*sig2./sig1;
H = H - bsxfun(@times,p,p');
H(1:(N+1):end) = diag(H) + sig1 - sig2.^2./sig1;
-------------------------------------

best,

Gongguo
"proecsm" wrote in message <ii7o08$lf$1@fred.mathworks.com>...
> "Gongguo Tang" wrote in message <ii7d79$lto$1@fred.mathworks.com>...
> > Hi there,
> >
> > I have a code that computes Q'*D(t)*Q many times. Here Q is a fixed mxn matrix with m < n, while the diagonal matrix D depends on the iteration t.
> >
> > Because I have so many iterations that the operation slows done the entire process.
> >
> > I am wondering if there is any way to obtain Q'*D(t)*Q as fast as possible. Maybe from the result of Q'*Q or some kind of decomposition of Q'*Q?
> >
> > Thanks in advance!
> >
> > best,
> >
> > Gongguo
>
> I think it is unlikely that there is a shortcut using Q'*Q or decomposition thereof. More likely is if you could a snippet of your code, someone could suggest a more efficient approach

Subject: Fast Matrix*Diagonal*Matrix operation

From: Gongguo Tang

Date: 3 Feb, 2011 20:58:04

Message: 6 of 8

Hi Bruno,

Could you explain why it is so? Thanks.

best,

Gongguo
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ii8c3b$a9r$1@fred.mathworks.com>...
> "Gongguo Tang" wrote in message <ii7d79$lto$1@fred.mathworks.com>...
>
> >
> > I am wondering if there is any way to obtain Q'*D(t)*Q as fast as possible. Maybe from the result of Q'*Q or some kind of decomposition of Q'*Q?
> >
>
> I'm pretty sure the answer is: no, it's not possible.
>
> Bruno

Subject: Fast Matrix*Diagonal*Matrix operation

From: Matt J

Date: 3 Feb, 2011 21:15:20

Message: 7 of 8

"Gongguo Tang" wrote in message <iif4qv$a1d$1@fred.mathworks.com>...
> Hi proecsm,
>
> Thanks for your reply. The first two lines below are my codes for computing Q'*D(t)*Q, where D(t) = diag(sig3) and sig3 changes every iteration. I still need several other lines to implement additional computations.
>
> I would appreciate if anyone could speed up the code.
>
> ----------------
> Qtmp = bsxfun(@times,Q.',sig3');
> H = Qtmp*Q;
> p = sqrt(-eta)*sig2./sig1;
> H = H - bsxfun(@times,p,p');
> H(1:(N+1):end) = diag(H) + sig1 - sig2.^2./sig1;
> -------------------------------------

I think we have to see more. The real question is, what do you intend to do with H? If all you eventually do with H is multiply it with a vector, then you don't have to compute H at all.

Subject: Fast Matrix*Diagonal*Matrix operation

From: Matt J

Date: 3 Feb, 2011 21:16:04

Message: 8 of 8

 >H = H - bsxfun(@times,p,p');

also, note that if p is a vector, then this is just

H=H-p*p'

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