Multiplying two square matrices by performing vector operations
2 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
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
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
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 Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!