% data
A = [ 1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9];
B = [ 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9];
C = zeros(9,9);
% The method of matrix multiplication in Matlab
tic
C = A*B;
toc
% Our impletation method of matrix multiplication
tic
for ra = 1:9 % raws of the matrix A
for cb = 1:9 % columns of the matrix B
for len = 1:2
C(ra,cb) = A(ra,len)*B(len,cb)+C(ra,cb);
end
end
end
toc
% Optimal method 1
tic
for cb = 1:9 % columns of the matrix B
for ra = 1:9 % raws of the matrix A
for len = 1:2
C(ra,cb) = A(ra,len)*B(len,cb)+C(ra,cb);
end
end
end
toc
% Advanced optimal method 2
A = A'; % you can also directly given A = [ 1 2 3 4 5 6 7 8 9
% 1 2 3 4 5 6 7 8 9];
B = [ 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9];
tic
for i = 1:9 % columns of the matrix A
for j = 1:9 % columns of the matrix B
for len = 1:2
C(i,j) = A(len,i)*B(len,j)+C(i,j);
end
end
end
toc
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有