作业帮 > 综合 > 作业

非线性约束优化 目标函数和约束函数 在matlab中出错

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/29 17:11:59
非线性约束优化 目标函数和约束函数 在matlab中出错
%约束函数文件如下
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.
x =
3.2051 2.3000
fval =
7.6569
exitflag =
-2 结果不收敛
非线性约束优化 目标函数和约束函数 在matlab中出错
原因约束条件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] 图示曲面为目标函数,透明部分为不满足约束条件的区域,红点为最优值.