Diagonal of product of matrices

470 views
Skip to first unread message

robertoam...@gmail.com

unread,
Jan 20, 2009, 3:31:00 PM1/20/09
to The MATLAB users
Hello,

I need to compute diag(A*B), where A is nxm and B is mxn. Is there a
way to do it while avoiding the computation of all the non-diagonal
entries of A*B???

Thanks,

Roberto.

robertoam...@gmail.com

unread,
Jan 20, 2009, 3:36:19 PM1/20/09
to The MATLAB users
In general, I need an efficient way to get SOME entries of A*B without
computing the whole product.

Thanks again,

Roberto.

On 20 ene, 17:31, "robertoamaru.cor...@gmail.com"

robertoam...@gmail.com

unread,
Jan 22, 2009, 1:01:57 PM1/22/09
to The MATLAB users
Well, since no one seems to attend this group, I searched the web and
found some nice solutions in

http://www.mathworks.com/matlabcentral/newsreader/view_thread/165784
http://www.mathworks.com/matlabcentral/newsreader/view_thread/168539

I hope this thread be useful for someone in the future...

Thanks anyway,

Roberto.

On 20 ene, 17:36, "robertoamaru.cor...@gmail.com"

Kevin Sharp

unread,
Feb 18, 2009, 7:49:28 PM2/18/09
to The MATLAB users
This can be done easily with a function like this ...


function C = diag_product(A,B )
%DIAG_PRODUCT Return the same as diag(A*B) but without calculating the
whole of A*B
%
C = sum(A .* B', 2);
end


On Jan 23, 7:01 am, "robertoamaru.cor...@gmail.com"
<robertoamaru.cor...@gmail.com> wrote:
> Well, since no one seems to attend this group, I searched the web and
> found some nice solutions in
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/165784http://www.mathworks.com/matlabcentral/newsreader/view_thread/168539
Reply all
Reply to author
Forward
0 new messages