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 中查找有关 基于问题的优化设置 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!