How can we reduce the execution time of this whole code?
Ältere Kommentare anzeigen
I want to minimize the "execution time" of the code given in the attachment. You can run the m file "main".
2 Kommentare
Dyuman Joshi
am 8 Feb. 2023
In myfunction, Why are you pre-allocating an empty matrix?
K = length(u); %Constant4
c=zeros(M*N, length(u)-K);
ce=zeros(M*N, length(u)-K);
%Modify it as
c=zeros(M*N,K);
ce=zeros(M*N,K);
And club the two for loop together -
for g= 1:K
c(:,g)=kron(a(:,g),f(:,g));
end
for g= 1:K
ce(:,g)=kron(ae(:,g),fe(:,g));
end
into
for g = i %i is already defined in the code
c(:,g)=kron(a(:,g),f(:,g));
ce(:,g)=kron(ae(:,g),fe(:,g));
end
Additionally, pre-allocate Sol and Fitness in fp1
After these changes, the code runs in 2.5674 secs in i3-5th gen, 8gb RAM, which imo is fast enough.
Sadiq Akbar
am 8 Feb. 2023
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!