非线性约束优化 目标函数和约束函数 在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 结果不收敛
%约束函数文件如下
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 结果不收敛
原因约束条件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] 图示曲面为目标函数,透明部分为不满足约束条件的区域,红点为最优值.
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] 图示曲面为目标函数,透明部分为不满足约束条件的区域,红点为最优值.
非线性约束优化 目标函数和约束函数 在matlab中出错
非线性约束规划 我编制了 目标函数和约束函数 为什么在matlab中还是出错 求大神看看这不给力的
用matlab求解一个优化问题(目标函数非线性,约束函数线性)
如何用Matlab求有限制条件的目标函数的最小值求解一个优化问题(目标函数非线性,约束函数线性)?
急!matlab 如何完成非线性约束优化
%人字架体积优化设计%1----主程序%人字架优化调用目标函数文件与非线性约束文件%设计变量的初始值x0=[100;80
matlab约束优化问题
用matlab的optimization工具箱遗传算法优化函数,被优化的函数和条件约束如下,请问为会有报错(图片)
matlab优化约束matlab优化的约束,有等式约束,不等式约束;x+8
谁能帮我编段优化设计程序啊,一直目标函数、约束、变量,求满足约束且目标最小时的变量取值,万分感谢
matlab有约束多元函数极值问题
MATLAB做非线性约束优化时,怎么老显示这个啊?