inv(A) versus /A. Which of the two is the correct one

조회 수: 1 (최근 30일)
ektor
ektor 2015년 2월 12일
댓글: Stephen23 2015년 2월 13일
Hi all,
Let B be a n by 2 matrix and A is a 2 by 2 positive definite matrix. Which of the following two is correct
for i=1:n
B(i,:)*inv(A)*B(i,:)';
end
or
for i=1:n
(B(i,:)/A)*B(i,:)';
end
Best, Stef
  댓글 수: 1
Stephen23
Stephen23 2015년 2월 13일
Don't use a loop, learn to vectorize your code. Matt J's answer shows this.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2015년 2월 12일
Both are equivalent. For large matrices the 2nd would be more efficient.
Further efficiency would be gained by vectorizing. The whole loop is just,
sum( (B/A).*B, 2)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by