How can we reduce the execution time of this whole code?
Show older comments
I want to minimize the "execution time" of the code given in the attachment. You can run the m file "main".
2 Comments
Dyuman Joshi
on 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
on 8 Feb 2023
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!