The most efficient way to calculate multiplication and summation of two large matrices
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mingyang Sun
el 11 de Mzo. de 2023
Comentada: Mingyang Sun
el 12 de Mzo. de 2023
Support I have two matrices
and
, I would like to calculate following:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321125/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321130/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321135/image.png)
where matrix
,
and
represent each columne of two matrices
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321140/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321145/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1321150/image.png)
I was wondering, what is the most efficient way to calculate matrix C? Many thanks!
0 comentarios
Respuesta aceptada
Bruno Luong
el 11 de Mzo. de 2023
Editada: Bruno Luong
el 11 de Mzo. de 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
% or
tic
C2 = sum(pagemtimes(reshape(A,size(A,1),1,[]),reshape(B,1,size(B,1),[])),3)/size(A,2);
toc
% or
tic
C3 = sum(reshape(A,size(A,1),1,[]).*reshape(B,1,size(B,1),[]),3)/size(A,2);
toc
norm(C1-C2,'fro')
norm(C1-C3,'fro')
Más respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!