Effacer les filtres
Effacer les filtres

i have function file i want put limit in variables

3 vues (au cours des 30 derniers jours)
Pratik Anandpara
Pratik Anandpara le 17 Mar 2017
Commenté : Steven Lord le 17 Mar 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

Réponses (1)

Jan
Jan le 17 Mar 2017
Modifié(e) : Jan le 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 commentaires
Pratik Anandpara
Pratik Anandpara le 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 le 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.]

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by