目标函数文件:
function f=jsq_f(x);
K=468,L=1400,y=-3,z=-4,r=4;
for i=0:(pi/360):(pi/4)
D=atan((x(2)*L)/(0.5*K));
A=x(1)*(2*r*sin(i)+K);
B=2*y*x(1);
C=r*K*sin(i)-2*z*r*cos(i)-x(1)*K*cos(D)-2*x(1)*y*sin(D)-2*r*abs(z);
cos(H)=(-2*B*C+sqrt(4*B.^2*C.^2)-4*(A.^2+B.^2)*(C.^2-A.^2))/(2*(A.^2)+(B.^2));
E=pi-(D)-acos(H);
F=acot(cot(E)-K/L);
G=D-asin(sin(D+E)/sqrt((K/x(1)).^2+1-2*K*cos(D+E)/x(1))-acos(K*(2*cos(D)-cos(D+E)-cos(2*D))/x(1)/sqrt((K/x(1)).^2+1-2*K*cos(D+E)/x(1));
if 0<E & E<=pi/18
f=\sum(1.5*((G-F)/F));
else if pi/18<E & E<=pi/9
f=\sum((G-F)/F);
else f=(0.5*((G-F)/F));
end
end
目标函数调用文件:
x0=[51;0.46];
lb=[51.48;0.46];
ub=[70.2;1];
[x,fval]=fmincon(@jsq_f,x0,a,b,lb,ub);
一直一直报错:
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
In jsq_fy at 4
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Error: File: C:\Users\fanjianwei\Desktop\jsq_f.m Line: 11 Column: 139
Incomplete or misformed expression or statement. Error in ==> jsq_fy at 4
[x,fval]=fmincon(@jsq_f,x0,a,b,lb,ub);
求帮忙找错