S=3.55; a=0.4; m=2.8; c=0.3;
bt=atan(W/(S+L)); save('information.mat');
适应性M文件fun.m function f=fun(x) load information.mat;
f=[x(2)+x(3);x(1)*L*cos(x(2))+(pi/2-x(1))*L*cot(x(3))+x(4)]; End
适应性M文件mycon2.m load information.mat;
g=[ y0+L*cot(x(2))*(1-cos(x(1)))+sqrt(((S+L)/2)^2+(W/2)^2)*sin(x(1)+bt)-n-b;...
sqrt((m-x0-(L*cot(x(2))+L*cot(x(3)))*sin(x(1)))^2+(n-y0+(L*cot(x(2))+L*cot(x(3)))*cos(x(1))-L*cot(x(2)))^2)-L*cot(x(3))+W/2;...
-x0-L*cot(x(2))*sin(x(1))+L*cot(x(3))*(1-sin(x(1)))+W/2+a;... x0+L*cot(x(2))*sin(x(1))-L*cot(x(3))*(1-sin(x(1)))+W/2+a-m;...
y0+L*cot(x(2))*(1-cos(x(1)))-x(4)-L*cot(x(3))*cos(x(1))+(S+L)/2-n+c;... -y0-L*cot(x(2))*(1-cos(x(1)))+x(4)+L*cot(x(3))*cos(x(1))+(S-L)/2+c]; ceq=[]; end 主程序 clear,clc
%x=[aef st1 st2 d x0 y0]
26
load information.mat;
prompt={'输入x0的取值:','输入y0的取值:'}; name='参数设定'; numlines=1;
answer=inputdlg(prompt,name,numlines); x0=str2double(answer(1)); y0=str2double(answer(2));
save('information.mat','x0','-append'); save('information.mat','y0','-append'); x_begin=[pi/1000;pi/1000;pi/1000;-9]; lb=[pi/6 pi/6 0 0 ]; ub=[2*pi/9 2*pi/9 pi/2 n+b ];
[x,fval,attain_factor]=fgoalattain('fun',x_begin,[0 1],[],[],[],[],lb,ub,'mycon2');
附录4:问题二的完整数据结果
>> x x =
0.7429 0.4788 0.6810 9.7543
27
0],[1
>> fval fval =
1.1598 13.6880
>> x x =
0.7182 0.5036 0.7830 5.5763 >> fval fval =
1.2866 9.0529
28
>> x x =
0.5236 0.5800 1.0713 3.6178 >> fval fval =
1.6513 5.9797
>> x x =
29
0.5236 0.6981 0.9331 4.1170 >> fval fval =
1.6312 6.8713
>> x x =
0.5236 0.6981 0.5915 3.6016 >> fval fval =
30