1) For bounds constraints, you do not need any constraints functions.
ObjFcn = @myFitness;
nvars = 28;
LB = [-0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2];
UB = [0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2];
A = []; b = []; Aeq = []; beq = [];
[x, fval] = ga(ObjFcn, nvars, A, b, Aeq, beq, LB, UB);
2) With respect to global variable:
better would be to use nested functions with shared variables. global is the slowest form of variable access.
But if you do use global, then make sure that you declare the variables as global in the workspace where you want to view them. If your "main function" is a function rather than a script and you are viewing from the command window without the debugger, then you would want to also give the global command at the command line.
3) If you are making changes to a variable "for the purpose of calculation of the parameter I wish to minimise" then you are introducing discontinuities in your calculation. ga() can survive discontinuities where most other routines cannot (particleswarm can survive discontinuities as well), but you lose efficiency and end up hoping that a mutation will drop you in the right spot. But in any case, if you have declared them as global and modify them, then you can retrieve them afterwards by access them from the global workspace.
4) "The value of the current positions are being updated only inside the fitness function."
Anything that you are changing inside your fitness function with hopes of returning should probably be part of your variables being minimized.
5) "I am slowly increasing the value of position in roughly 600 iterations in my main program."
I wonder if Simulated Annealing, sa(), might be better for your purpose?
Best Answer