Code for Multiple Matrix Multiplication
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Prasanna Venkatesh
am 14 Jun. 2019
Kommentiert: Prasanna Venkatesh
am 14 Jun. 2019
I have 'n' number of two dimensional(square) matrices. I have stored them as stack in a single three dimensional matrix. How can I perform series of matrix multiplication from 1 to n matrices without explicitly writing the whole line?
n=3;
a,b,c; % Three 2d matrices with same dimension
T(:,:,1) = a;
T(:,:,2) = b;
T(:,:,3) = c;
ans = T(:,:,1)*T(:,:,2)*T(:,:,3);% Explicitly performing matrix multiplication
0 Kommentare
Akzeptierte Antwort
Stephen23
am 14 Jun. 2019
Bearbeitet: Stephen23
am 14 Jun. 2019
>> T=randi(9,4,4,3); % fake data
>> T(:,:,1)*T(:,:,2)*T(:,:,3) % your approach
ans =
2359 1398 2072 2154
1788 1103 1625 1734
1731 1137 1653 1808
2154 1282 1849 1995
>> M=1; for k=1:size(T,3), M=M*T(:,:,k); end % simple loop
>> M
M =
2359 1398 2072 2154
1788 1103 1625 1734
1731 1137 1653 1808
2154 1282 1849 1995
Weitere Antworten (1)
madhan ravi
am 14 Jun. 2019
RR = cell(1,size(T,3)-1); % where T is your 3D matrix
RR{1} = T(:,:,1)*T(:,:,2);
for k = 2:size(T,3)-1
RR{k} = RR{k-1} * T(:,:,k+1);
end
Wanted = RR{end}
0 Kommentare
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!