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:
Simple problem: diagonal elements of A*A'

Subject: Simple problem: diagonal elements of A*A'

From: Misha Koshelev

Date: 2 Mar, 2010 20:24:04

Message: 1 of 4

My apologies, I know this is simple and I am not thinking straight at the moment. Any help appreciated.

Take, for example
A=[1 2; 3 4]

I would like to get the result of diag(A*A')

without doing the intensive computation A*A' that might come with large matrices A. Any help much appreciated.

Thank you!
Sincerely yours
Misha Koshelev

Subject: Simple problem: diagonal elements of A*A'

From: Matt Fig

Date: 2 Mar, 2010 20:43:04

Message: 2 of 4

I don't know if this is less computationally intensive or not, though I suspect it is.

sum((A).^2,2) == diag(A*A')

Subject: Simple problem: diagonal elements of A*A'

From: Misha Koshelev

Date: 2 Mar, 2010 23:11:02

Message: 3 of 4

"Matt Fig" <spamanon@yahoo.com> wrote in message <hmjt8n$hp4$1@fred.mathworks.com>...
> I don't know if this is less computationally intensive or not, though I suspect it is.
>
> sum((A).^2,2) == diag(A*A')

Thank you!

My apologies I actually meant diag(A'*A)

I tried

R=Inf*ones(size(A,2),size(A,2));
for i=1:size(A,2)
   R(i,i)=dot(A(:,i),A(:,i));
end

or even simpler

R=Inf*ones(size(A,2),size(A,2));
for i=1:size(A,2)
   R(i,i)=A(i,:)'*A(:,i);
end

but these take _four times_ as long for large matrices.

Any other ideas?

Thank you
Misha

Subject: Simple problem: diagonal elements of A*A'

From: Matt Fig

Date: 2 Mar, 2010 23:30:08

Message: 4 of 4

Same problem.


A = round(rand(3)*20);
B = diag(A'*A);
C = sum(A.^2,1).';
isequal(B,C)

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