N =
minimizing with genetic algorithm
Mostrar comentarios más antiguos
Good morming
I would like to minimize my function with GA
function y=obj1(x)
y=(1.002)-((1-exp(-0.00003*x))/(0.00003*(x+1.5)+(0.00063*(1-exp(-0.00003*x)))));
for x=24:720
the résule in Matlab whene I use :
[x,y]=ga(@obj1,1,24,720)
Optimization terminated: average change in the fitness value less than options.TolFun.
x =
-1.499097579634137
y =
-3.566513164743854e+004
negative results.
Respuestas (2)
y = @(x) (1.002)-((1-exp(-0.00003*x))./(0.00003*(x+1.5)+(0.00063*(1-exp(-0.00003*x)))));
fplot(y, [-2, 10])
fplot(y, [-1.5 -1.498])
fplot(y, [5 1000])
syms x
[N,D] = numden(y(x))
vpasolve(D)
So near -1.49906 is indeed a minimum, since it is a critical point of the function. ga() was correct to find it.
On the positive side, the minimum is somewhere near 300.
If you want to constraint to positive values, then use a lb parameter to ga:
A = [];
b = [];
Aeq = [];
beq = [];
lb = 24;
ub = 720;
[x,y]=ga(y, 1, A, b, Aeq, beq, lb, ub)
Your bug was in providing lb and ub in the slots reserved for A and b.
1 comentario
dal
el 30 de Dic. de 2024
Hey @dal
For time-invariant real-valued univariate functions, it is recommended to plot the graph to estimate the approximate location of the minimum point. From the graph, we can visually estimate that the local minimum lies between 200 and 400 with a high degree of confidence. Narrowing the search range can sometimes enhance the algorithm's efficiency. If you can provide the rate of change of the function, some algorithms can search even more effectively
In the example below, I used 'fminbnd()' (I call it f min bound) instead of the genetic algorithm, 'ga()'. Please ensure that you enter the intended inputs correctly and in the correct sequence. In your case, the function did not flag an error because there was no error from the perspective of program execution. This can often be challenging for beginners, as they may not understand what went wrong, even though they are certain that the result is incorrect.
lb = 24; % lower bound of plot
ub = 720; % upper bound of plot
ss = 0.01; % step size
%% the function
f = @(x) 1.002 - ((1 - exp(- 0.00003*x))./(0.00003*(x + 1.5) + (0.00063*(1 - exp(- 0.00003*x)))));
x = linspace(lb, ub, (ub - lb)/ss + 1);
%% the plot
plot(x, f(x)), grid on, grid minor
xlabel('x'), ylabel('f(x)')
lb = 200; % lower bound of search
ub = 400; % upper bound of search
%% location of the local minimum value
xmin = fminbnd(f, lb, ub)
%% the minimum value in the given range
fmin = f(xmin)
1 comentario
dal
el 30 de Dic. de 2024
Categorías
Más información sobre Genetic Algorithm en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



