필터 지우기
필터 지우기

i have function file i want put limit in variables

조회 수: 3 (최근 30일)
Pratik Anandpara
Pratik Anandpara 2017년 3월 17일
댓글: Steven Lord 2017년 3월 17일
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

답변 (1개)

Jan
Jan 2017년 3월 17일
편집: Jan 2017년 3월 17일
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
Pratik Anandpara
Pratik Anandpara 2017년 3월 17일
2<x1<11 ,3<x2<12, 4<x3<12 for this three unknown variables..how to write instruction for this
Steven Lord
Steven Lord 2017년 3월 17일
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.]

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by