Borrar filtros
Borrar filtros

i have function file i want put limit in variables

3 visualizaciones (últimos 30 días)
Pratik Anandpara
Pratik Anandpara el 17 de Mzo. de 2017
Comentada: Steven Lord el 17 de Mzo. de 2017
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

Respuestas (1)

Jan
Jan el 17 de Mzo. de 2017
Editada: Jan el 17 de Mzo. de 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 comentarios
Pratik Anandpara
Pratik Anandpara el 17 de Mzo. de 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 el 17 de Mzo. de 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.]

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by