Clear Filters
Clear Filters

i have function file i want put limit in variables

3 views (last 30 days)
function y=myfitness(x)
y= x(1)+x(2)+x(3);
end
this is function file and i want 2<x1<11 ,3<x2<12, 4<x3<12 in this range and want y minimum answer in this range with help of genetic algorithm, i use 'ga' instruction also
fitfcn=@myfitness;
nvars=3;
[x fval]= ga(fitfcn,nvars);
i want minimize the function output value with this range with the help of Genetic algorithm

Answers (1)

Jan
Jan on 17 Mar 2017
Edited: Jan on 17 Mar 2017
You can limit the values using inputs for ga() - see doc ga:
x = ga(fitnessfcn,nvars,A,b) finds a local minimum x to fitnessfcn,
subject to the linear inequalities A*x ≤ b. ga evaluates the matrix
product A*x as if x is transposed (A*x').
Or better use the lower and upper bounds:
x = ga(fitnessfcn,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.
  3 Comments
Pratik Anandpara
Pratik Anandpara on 17 Mar 2017
2<x1<11 ,3<x2<12, 4<x3<12 for this three unknown variables..how to write instruction for this
Steven Lord
Steven Lord on 17 Mar 2017
See the first Example on the documentation page to which Jan linked. It constrains the two variables to be greater than 0 using the variable lb. Just specify a three element vector for lb instead of a two element vector and specify a three element vector for ub as well. [The example didn't have an upper bound on the variable value, so it didn't need to specify ub and didn't specify it.]

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!