Matlab优化
您好,我正在使用Matlab优化解算器,我的程序有问题。我收到此消息fmincon stopped,因为目标函数值小于目标函数限制的默认值,并且约束满足在约束公差的默认值内。我也得到了以下信息。警告:矩阵接近单数或比例严重。程序发送的值不正确。我需要最小x和z。功能如下Matlab优化,matlab,optimization,Matlab,Optimization,您好,我正在使用Matlab优化解算器,我的程序有问题。我收到此消息fmincon stopped,因为目标函数值小于目标函数限制的默认值,并且约束满足在约束公差的默认值内。我也得到了以下信息。警告:矩阵接近单数或比例严重。程序发送的值不正确。我需要最小x和z。功能如下 x*sqrt((16+y^2))+z*sqrt((1+y^2)). 任何帮助都将不胜感激。 以下约束条件如下所示 20*sqrt((16+y^2))-100000*y*x 80*sqrt((1+y^2))-100000y
x*sqrt((16+y^2))+z*sqrt((1+y^2)).
任何帮助都将不胜感激。
以下约束条件如下所示
20*sqrt((16+y^2))-100000*y*x
80*sqrt((1+y^2))-100000y*z
1<=y
y<=3
(x,z)transpose >0
function [c,ceq]=confun(x)
c=[(20*((16+x(2)^2)^.5))-100000*(x(2)*x(3)); (80*1+x(2)^2)^.5)-100000*x(2)*x(3); -x(2)+3; -x(2)+1; x(3)>0; x(1)>0];
ceq=[];
function f=obj(x)
f=x(1)*((16+x(2)^2)^.5)+x(3)*((1+x(2)^2)^.5);
x0=[1;1;1];
[x,fval]=fmincon(@obj,x0,[],[],[],[],[],[],@confun)
20*sqrt((16+y^2))-100000*y*x
80*sqrt((1+y^2))-100000y*z
10; x(1)>0];
ceq=[];
函数f=obj(x)
f=x(1)*(16+x(2)^2^.5)+x(3)*(1+x(2)^2^.5);
x0=[1;1;1];
[x,fval]=fmincon(@obj,x0,[],[],[],[],[],[],[],[],@confun)
您的主要问题是,您在非线性约束函数中成功放置返回1
的二进制测试,该函数期望前两行不是约束(no=,等等)?那些是什么?(例如,20*sqrt((…
这不是完整的代码,你能发布一个可运行的版本吗?代码块顶部的非代码让我很困惑。太好了,只需单击答案旁边的复选标记即可将其标记为已接受。很高兴我能提供帮助。
function example()
% initial conditions
x0=[1;1;1];
% linear constraint system (Ax <= b)
A = [0 -1 0;
0 1 0;
-1 0 0;
0 0 -1];
b = [-1 3 0 0]';
display('Run with broken nonlinear-only constraints');
[x,fval]=fmincon(@obj,x0,[],[],[],[],[],[],@conBroken)
display('Run with fixed nonlinear-only constraints');
[x,fval]=fmincon(@obj,x0,[],[],[],[],[],[],@conFixed)
display('Run with linear/nonlinear constraints');
[x,fval]=fmincon(@obj,x0,A,b,[],[],[],[],@conNonlin)
% oops, x(...)>0 is 1 upon success
function [c,ceq]=conBroken(x)
c=[(20*((16+x(2)^2)^.5))-100000*(x(2)*x(3)); (80*1+x(2)^2)^.5-100000*x(2)*x(3); -x(2)+3; -x(2)+1; x(3)>0; x(1)>0];
ceq=[];
% good, -x(...) <= 0 when x>0
function [c,ceq]=conFixed(x)
c=[(20*((16+x(2)^2)^.5))-100000*(x(2)*x(3)); (80*1+x(2)^2)^.5-100000*x(2)*x(3); -x(2)+3; -x(2)+1; -x(3); -x(1)];
ceq=[];
% moved linear constraints to where they should be
function [c,ceq]=conNonlin(x)
c=[(20*((16+x(2)^2)^.5))-100000*(x(2)*x(3)); (80*1+x(2)^2)^.5-100000*x(2)*x(3);];
ceq=[];
% objective function
function f=obj(x)
f=x(1)*((16+x(2)^2)^.5)+x(3)*((1+x(2)^2)^.5);
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 3000 (the default value).
x =
-23.3480
6.3806
0.0470
fval =
-175.5250
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 3000 (the default value).
x =
0.1893
1.8200
0.5598
fval =
1.9947
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance, and
constraints are satisfied to within the default value of the constraint tolerance.
x =
0.0000
1.9993
0.0004
fval =
0.0010