필터 지우기
필터 지우기

Multiplying two square matrices by performing vector operations

조회 수: 2 (최근 30일)
Pascale Bou Chahine
Pascale Bou Chahine 2020년 9월 19일
댓글: Walter Roberson 2020년 9월 19일
function C=multiply(A,B)
[n,n] = size(A);
[n,n]=size(B);
%C=zeros(n,n);
for j=1:n
for i=1:n
C(i,j)= A(i,:).*B(:,j);
end
end
I have to multiply these two n by n matrices (by performing vector operations), where B is an upper trianguar matrix. But when I run my code, I get that the indices on the left side are not compatible with the size of the right side. But I don't see where I went wrong. Any help please?

답변 (1개)

Walter Roberson
Walter Roberson 2020년 9월 19일
When you do algebraic matrix multiplication ("inner product") then you have to sum() the result of the individual multiplications.
You will find that you also need to transpose one of the two vectors.
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 9월 19일
It is not possible to meaningfully measure flops on any modern computer. The introduction of the MIPS R8000 in 1992 was pretty much the end of the era for being able to measure flops. The Sun SPARC "SuperScalar" was already not easy to measure flops on, but it was possible to assign some meaning to flops on it; the speculative execution of the MIPS R8000 broke down the last pretense that flops were still meaningful.
Walter Roberson
Walter Roberson 2020년 9월 19일
C(i,j)+sum(A(i,:).*B(:,j)')
The addition of the C(i,j) is not useful at that point. By examining your code you can see that C(i,j) is always going to be 0 at that point in the code.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by