Vectorising Multiplying each column from a matrix with a square matrix and the tranpose of this column
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have an operation that I'm doing with a loop but would like to vectorise if possible.
I have a matrix h (2790x3591) and a matrix Pn(2790x2790).
I need to implement the following operation: h_column' * Pn * h_column, for all columns of h.
Is there a way to vectorise this operation? It takes about 45s to do with the for loop.
NB: The matrices are complex with very small imaginary parts, so that adds a bit of delay because the multiplications are more involved.
댓글 수: 0
답변 (3개)
Kevin Holly
2022년 2월 23일
Can you do the following?
h = rand(2790,3591);
Pn = rand(2790,2790);
size(h'*Pn*h)
James Tursa
2022년 2월 23일
If you need the same column on each side of the multiply, then maybe this:
result = sum(h'*Pn.*h',2);
댓글 수: 2
Matt J
2022년 2월 23일
편집: Matt J
2022년 2월 23일
I need to take diag(h'*Pn*h).
No, that will be super slow and inefficient. This should be what you want,
result = sum(h.*(Pn*h),1);
James' version was almost equivalent except for a missing transpose,
result = sum(h'*Pn'.*h',2);
but no need to incur the expense of all those transpositions, as far as I can see.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!