3 "for" loops optimization or changing for global maximum finding
Mostra commenti meno recenti
Hi,
I have a function (function1), which has three variables (i,j,k) which I need to change from -20 to 20 in step 1, and later with function2, I have to find maximum DB number and place (ci, cj, ck), where DB is the highest (it can be everyhere, depending on initial data file).
This code works good, but the main disadvantage of it is time. Calculations take about 3 hours (a lot of combinations ofc.). I need somehow to optimise my code. Can someone explain how can I find global maximum of DB faster, than doing 3 "for" loops?
I have heard about some algorithms which works, but I don't know how and how to use it in matlab.
Thanks.
max = 0;
ci = 0;
cj = 0;
ck = 0;
% kr1 = 0;
% kg2 = 0;
% kb3 = 0;
for i = -20:1:20
for j = -20:1:20
for k = -20:1:20
[spd, kr, kg, kb] = function1( i, j, k, A, B, C );
DB = function2( mspd4, mspd5, Xn, Yn, Zn, U, range, D, E, F, spd );
if(max<=DB)
max = DB;
ci = i; cj = j; ck = k;
% kr1 = kr; kg2 = kg; kb3 = kb;
end
end
end
end
6 Commenti
Michael Croucher
il 5 Ott 2020
Can you share function1 and function2 to make this an example that's runnable please?
Domantas B
il 6 Ott 2020
Domantas B
il 6 Ott 2020
Walter Roberson
il 6 Ott 2020
[spd, kr, kg, kb] = function1( i, j, k, A, B, C );
DB = function2( mspd4, mspd5, Xn, Yn, Zn, U, range, D, E, F, spd );
Most of those variables are not defined. A, B, C, mspd4, mspd5, Xn, Yn, Zn, U, range, D, E, F are all not defined at that point.
In order to have a hope of optimizing your code, we need to be able to run your code.
You should also indicate which of the variables are always going to be the same for this purpose, and which you might change in the future.
Inside function1:
spektras1 = mspd1; %initial file 1
spektras2 = mspd2; %iniitial file 2
spektras3 = mspd3; %initial file 3
None of those mspd* variables are defined.
Domantas B
il 6 Ott 2020
Modificato: Domantas B
il 6 Ott 2020
Domantas B
il 6 Ott 2020
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Surrogate Optimization in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!