我的模型
Min
s.t.
%编写约束条件M文件(yueshu.m)。
function [c,ceq]=yueshufun(x1,x2,x3)
c=[(x2^2+x3^2-(1-x1)^2)/2*x2*x3-sqrt(3)/2;
sqrt(2)/2-(x2^2+x3^2-(1-x1)^2)/2*x2*x3];
ceq=[];
目标函数goal_func.m:
function H=goal_func(x1,x2,x3,x4)
F=0;
for i=1:20;
%w表示输入角θ。输入角变化180度,分20次,每次变化9度。
wi=1*pi*i./20;
G=(atan(x1*sin(x4)/(1-x1*cos(x4)))+acos((x1^2-x2^2+x3^2+1-2*x1*cos(x4))...
/(2*x3*sqrt(x1^2+1-2*x1*cos(x4))))-atan((x1*sin(x4+wi))/(1-x1*cos(x4+wi)))...
-acos((x1^2-x2^2+x3^2+1-2* x1*cos(x4+wi))/(2*x3*sqrt(x1^2+1-2*x1*cos(x4+wi))))-6*sin(pi*wi/180)/pi)^2;
F=F+G;
end %运算之后是数学模型中的目标函数。
H=F-r*(log(-x1-x2+x3+1)+log(-x1+x2-x3+1)+log(-x1+x2+x3-1)+log(x1-0.1)+log(-x1+0.5)...
+log(x2-0.1)+log(-x2+1.4)+log(x3-0.1)+log(-x3+0.9)...
+log(x2^2+x3^2-(1-x1)^2)/2*x2*x3-sqrt(3)/2+log(sqrt(2)/2-(x2^2+x3^2-(1-x1)^2)/2*x2*x3)); %这是惩罚函数的目标函数。惩罚函数法是解决约束优化问题的一种思路,是将目标函数和约束条件按照规定构造成新的目标函数,将约束优化问题转化为无约束优化问题
下面是fmincon函数的调用:
%调用fmincon函数进行求解。
x0=[0.3,1,0.6,2*pi/3];
lb=[];
ub=[];
options=optimset('Largescale','on','display','iter','tolx',1e-4); %搞不懂这里options干什么的。
for a=1:100;
b=10^a;
r=1/b;
[x,fval,exitflag,output,lambda]=fmincon('goal_func',x0,A,b,[],[],[],[],'yueshufun',options);
if fval>=0.001 %收敛精度为0.01。
break;
end
end
最后是几个已知参数:
下面是参数A:9*3的
1 1 -1
1 -1 1
1 -1 -1
-1 0 0
1 0 0
0 -1 0
0 1 0
0 0 -1
0 0 1
下面是b
1
1
-1
-0.100000000000000
0.500000000000000
-0.100000000000000
1.40000000000000
-0.100000000000000
0.900000000000000
最后还有初始值x0
0.300000000000000 1 0.600000000000000 2.09439510239320
最后是运行是出现的问题::
dyfmincon
Warning: Trust-region-reflective method does not currently solve this type of problem,
using active-set (line search) instead.
> In fmincon at 439
In dyfmincon at 9
??? Input argument "x4" is undefined.
Error in ==> goal_func at 6
G=(atan(x1*sin(x4)/(1-x1*cos(x4)))+acos((x1^2-x2^2+x3^2+1-2*x1*cos(x4))...
Error in ==> fmincon at 519
initVals.f = feval(funfcn{3},X,varargin{:});
Error in ==> dyfmincon at 9
[x,fval,exitflag,output,lambda]=fmincon('goal_func',x0,A,b,[],[],[],[],'yueshufun',options);
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
请教大侠。。。。