非线性约束优化 目标函数和约束函数 在matlab中出错 求大神指点一二
%约束函数文件如下function[c,ceq]=confun(x)c=[0.70868/(pi*(x(1)^4-x(2)^4)/(32*x(1)))-10,0.8-x(...
%约束函数文件如下
function [c,ceq]=confun(x)
c=[0.70868/(pi*(x(1)^4 - x(2)^4)/(32*x(1))) - 10, 0.8 - x(1) +x(2)];
ceq=[];
---------------------------
%目标函数文件如下
function f=objfun(x)
y(1) = 5*((49.5)^4)*(1.2121*(10^-3))/(384*7000*pi*(x(1)^4-x(2)^4)/64);
y(2) = pi*(x(1)^2 - x(2)^2)/4;
f=0.5*(y(1))^2 + 0.5*(y(2))^2;
----------------------------------
%优化函数文件
clear;
clc;
x0=[5,4];
lb=[3.2,2.3];
ub=[8,7.1];
options=optimset('Algorithm','interior-point','display','iter');
[x,fval,exitflag,output]=fmincon(@objfun,x0,[],[],[],[],lb,ub,@confun,options)
结果出错 时间比较急 求指点
运行结果:
No feasible solution found.
fmincon stopped because the size of the current step is less than
the default value of the step size tolerance but constraints were not
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
3.2051 2.3000
fval =
7.6569
exitflag =
-2 结果不收敛 展开
function [c,ceq]=confun(x)
c=[0.70868/(pi*(x(1)^4 - x(2)^4)/(32*x(1))) - 10, 0.8 - x(1) +x(2)];
ceq=[];
---------------------------
%目标函数文件如下
function f=objfun(x)
y(1) = 5*((49.5)^4)*(1.2121*(10^-3))/(384*7000*pi*(x(1)^4-x(2)^4)/64);
y(2) = pi*(x(1)^2 - x(2)^2)/4;
f=0.5*(y(1))^2 + 0.5*(y(2))^2;
----------------------------------
%优化函数文件
clear;
clc;
x0=[5,4];
lb=[3.2,2.3];
ub=[8,7.1];
options=optimset('Algorithm','interior-point','display','iter');
[x,fval,exitflag,output]=fmincon(@objfun,x0,[],[],[],[],lb,ub,@confun,options)
结果出错 时间比较急 求指点
运行结果:
No feasible solution found.
fmincon stopped because the size of the current step is less than
the default value of the step size tolerance but constraints were not
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
3.2051 2.3000
fval =
7.6569
exitflag =
-2 结果不收敛 展开
1个回答
展开全部
原因
约束条件
c=[0.70868/(pi*(x(1)^4 - x(2)^4)/(32*x(1))) - 10, 0.8 - x(1) +x(2)];
写错了,改成
c=[0.70868/(pi*(x(1)^4 - x(2)^4)/(32*x(1))) - 10, 0.8 - x(1) + x(2)];
按照你原来的写法,+x(2) 会被理解为单独的一项,约束条件本来是两个,被当成三个了。而第三个约束条件x(2)的值在给定区域内均大于0,所以根本找不到可行解,而不是收不收敛的问题。
在表达式中适当地加一些空格有助于阅读,但如果加的位置不合适,可能会改变表达式的本来含义,这一点一定要小心。
结果
改正上面这一点错误后,优化成功:
Optimization terminated: first-order optimality relative error
less than options.TolFun, and relative constraint violation less
than options.TolCon.
x =
3.2000 2.4000
fval =
6.1902
exitflag =
1
output =
iterations: 7
funcCount: 24
constrviolation: 0
stepsize: 7.1456e-007
algorithm: 'interior-point'
firstorderopt: 2.3809e-006
cgiterations: 0
message: [1x148 char]
图示
曲面为目标函数,透明部分为不满足约束条件的区域,红点为最优值。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |