matlab中遗传算法的运行问题,求指教!。

function y = optlincontest6(x)
y = x^2+1;
options = gaoptimset('Generations',100,'PopulationSize',400);
lb=10;
ub=30;
[x,fval,exitflag] = ga(@optlincontest6,1,options);
为什么我设定x的区间为10到30,得到的最优结果是x=-8.7828e-5,y=1.0000?
哪里有错误,求指教!

 채택된 답변

lobim
lobim 2022년 11월 19일

0 개 추천

lb和ub没有传递进去,你直接写lb=10,ub=30;是没有用的。
p.fitnessfcn = @optlincontest6;
p.options = options;
p.lb = lb;
p.ub = ub;
p.nvars = 1;
[x, fval, exitflag] = ga(p);
如果要lb和ub起作用,你得用这种形式的调用:X = ga(PROBLEM);
X = ga(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a structure
that has the following fields:
fitnessfcn: <Fitness function>
nvars: <Number of design variables>
Aineq: <A matrix for inequality constraints>
bineq: <b vector for inequality constraints>
Aeq: <Aeq matrix for equality constraints>
beq: <beq vector for equality constraints>
lb: <Lower bound on X>
ub: <Upper bound on X>
nonlcon: <Nonlinear constraint function>
intcon: <Index vector for integer variables>
options: <Options structure created with GAOPTIMSET>
rngstate: <State of the random number generator>

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 基于问题的优化设置에 대해 자세히 알아보기

태그

질문:

2022년 11월 19일

답변:

2022년 11월 19일

Community Treasure Hunt

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

Start Hunting!