how to minimize a function using Genetic Algorithm in matlab

1 回表示 (過去 30 日間)
Indu Choudhary
Indu Choudhary 2020 年 3 月 12 日
I have the following code with function Y = 1000*log(1+4.5/((100-u*cos(theta)*(X))^2+(100+u*sin(theta)*X-4.9*...
(X)^2)^2));
I want to minimize this using GA optimtool. How could I do this because my function is calculated in a loop. So, how could I use the whole code as fitness function?
a = 0;
b = 6;
B = 1000;
u = 40;
theta = pi/12;
Int_simp = zeros(1,10);
disp(Int_simp);
for N = 1:10
sum_simp = 0;
dx=(b-a)/N;
for r = 1:N
X = a + ((r-1)*dx);
Y = 1000*log(1+4.5/((100-u*cos(theta)*(X))^2+(100+u*sin(theta)*X-4.9*...
(X)^2)^2));
if (mod(r,2) == 0)
coeff = 4;
else
coeff = 2;
end
if (r == 0)||(r == N)
coeff = 1;
end
sum_simp = sum_simp + (coeff*Y*dx*(1/3));
end
Int_simp(N) = sum_simp;
end
plot(Int_simp,'-sm');

回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by