MATLAB Answers

0

How can I NOT specify the constraint function in the ga function?

Asked by Riccardo Andreoni on 6 Jul 2019
Latest activity Commented on by Matt J
on 6 Jul 2019
I'm trying to use the genetic algorithm function ga, which requires the following inputs:
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)
I need to specify some options, but I don't have any non linear constraint function, so I need to leave the input nonlcon "empty".
How can I do that?
Thank you

  1 Comment

Hello,
You can read instruction of using ga function as follows link
There are several options that you could adapt with your situation. For example, if you don't have nonlinear constrains, you may choose one of them:
x = ga(fun,nvars,A,b) finds a local minimum x to fun, subject to the linear inequalities A*xb. ga evaluates the matrix product A*x as if x is transposed (A*x').
x = ga(fun,nvars,A,b,Aeq,beq) finds a local minimum x to fun, subject to the linear equalities Aeq*x = beq and A*xb. (Set A=[] and b=[] if no linear inequalities exist.) ga evaluates the matrix product Aeq*x as if x is transposed (Aeq*x').
x = ga(fun,nvars,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables, x, so that a solution is found in the range lb x ub. (Set Aeq=[] and beq=[] if no linear equalities exist.)

Sign in to comment.

1 Answer

Answer by Matt J
on 6 Jul 2019
Edited by Matt J
on 6 Jul 2019

Any of the constraint arguments can be left empty to signify to ga that there are no constraints of that type, e.g.,
x = ga(fun,nvars,A,b,[],[],lb,[],[],options)

  2 Comments

Thank you,
what if I don't have a lower and upper bound to specify?
If I try to run
x = ga(fun,nvars,,[],[],[],[],options)
it requires me to specify lb and ub
No, not true:
>> ga(@(x) norm(x), 2,[],[],[],[],[],[])
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
ans =
0.1525 0.0840

Sign in to comment.