need to optimise my code

Hello friends,
i am writing a matlab optimisation program. Following is the segment of my code. for large value of m and n, this segment is taking longer time to execute. I want to optimise this code. Is there any body can help me in optimising this segment of code?
for s=1:m
for i=1:n
for j=1:n
for k=1:n
for l=1:n
A = A + D(k,l) * C(i,j,t) * B(i,k,s) * B(j,l,s);
end
end
end
end
end
thanks in advance...:)

1 comentario

Teja Muppirala
Teja Muppirala el 4 de Jun. de 2012
Where did you come up with this? Is this just a direct translation from C or Fortran or something? This is probably just some simple matrix operation, but you've got it all written out in loops. Just like you did here:
http://www.mathworks.com/matlabcentral/answers/38829-about-nested-for-loop

Respuestas (1)

Andrei Bobrov
Andrei Bobrov el 4 de Jun. de 2012

0 votos

See nice Teja' solution:
A = sum(arrayfun(@(ii)sum(sum(C(:,:,ii).*(B(:,:,ii)*D*B(:,:,ii)'))),1:size(C,3)))
if t ->s

La pregunta está cerrada.

Etiquetas

Preguntada:

t g
el 4 de Jun. de 2012

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by