フィルターのクリア

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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by