how to minimize a function using Genetic Algorithm in matlab

5 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by