%约束函数文件如下
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 结果不收敛
原因
约束条件
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
图示
曲面为目标函数,透明部分为不满足约束条件的区域,红点为最优值。