The most efficient way to calculate multiplication and summation of two large matrices

1 Ansicht (letzte 30 Tage)
Support I have two matrices and , I would like to calculate following:
where matrix , and represent each columne of two matrices
I was wondering, what is the most efficient way to calculate matrix C? Many thanks!

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 11 Mär. 2023
Bearbeitet: Bruno Luong am 11 Mär. 2023
It is just a scaling of matrix multiplication, if you haven't recorgnize it
A=rand(300,1000);
B=rand(300,1000);
tic
C1=(A*B')/size(A,2);
toc
Elapsed time is 0.003844 seconds.
% or
tic
C2 = sum(pagemtimes(reshape(A,size(A,1),1,[]),reshape(B,1,size(B,1),[])),3)/size(A,2);
toc
Elapsed time is 0.186097 seconds.
% or
tic
C3 = sum(reshape(A,size(A,1),1,[]).*reshape(B,1,size(B,1),[]),3)/size(A,2);
toc
Elapsed time is 0.192863 seconds.
norm(C1-C2,'fro')
ans = 6.1978e-14
norm(C1-C3,'fro')
ans = 6.1978e-14

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by