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?
哪里有错误,求指教!

 Akzeptierte Antwort

lobim
lobim am 19 Nov. 2022

0 Stimmen

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>

Weitere Antworten (0)

Kategorien

Tags

Gefragt:

am 19 Nov. 2022

Beantwortet:

am 19 Nov. 2022

Community Treasure Hunt

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

Start Hunting!