big difference in execution time in approximately the same code
Mostrar comentarios más antiguos
hello,
I want to compare between two methods of matrix multiplication. I thought they ought to run approximately the same time, but when I compared their exec time, there was a noticable difference. perhaps someone could explain why is this happening and if there's a way to write it differently in order to both codes run about the same time? (I want to compare the command C=A*B where A,B,C are matrices, and the method where I multily the elements one by one)
here's my code and the traceback:
N = 1000;
A = rand(N);
B = rand(N);
%% use buildin syntax to compute output matrix
tic;
C1 = A*B;
toc;
%% calculate each element seperatly
C2 = zeros(N);
tic;
for i = 1:N
for j = 1:N
for k = 1:N
C2(i,j) = C2(i,j) + A(i,k)*B(k,j);
end
end
end
toc;
Traceback:

Thank you very much for your time and attention!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Systems of Nonlinear Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!