3 "for" loops optimization or changing for global maximum finding
이전 댓글 표시
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
Michael Croucher
2020년 10월 5일
Can you share function1 and function2 to make this an example that's runnable please?
Domantas B
2020년 10월 6일
Domantas B
2020년 10월 6일
Walter Roberson
2020년 10월 6일
[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
2020년 10월 6일
편집: Domantas B
2020년 10월 6일
Domantas B
2020년 10월 6일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!