1、优化设计无约束优化 min f(x)= +-2-4初选x0=1,1程序:Step 1: Write an M-file objfun1.m.function f1=objfun1(x)f1=x(1)2+2*x(2)2-2*x(1)*x(2)-4*x(1);Step 2: Invoke one of the unconstrained optimization routinesx0=1,1; options = optimset(LargeScale,off); x,fval,exitflag,output = fminunc(objfun1,x0,options)运行结果:x = 4.0000
2、 2.0000fval = -8.0000exitflag = 1output = iterations: 3 funcCount: 12 stepsize: 1 firstorderopt: 2.3842e-007 algorithm: medium-scale: Quasi-Newton line search message: 1x85 char非线性有约束优化1. Min f(x)=3+2-3+5Subject to: (x)=+180 (x)=5-3-250 (x)=13-41 (x)=14 (x)=2初选x0=10,10Step 1: Write an M-file objfun2
3、.mfunction f2=objfun2(x)f2=3*x(1)2+x(2)2+2*x(1)-3*x(2)+5;Step 2: Write an M-file confun1.m for the constraints.function c,ceq=confun1(x)% Nonlinear inequality constraintsc=x(1)+x(2)+18; 5*x(1)-3*x(2)-25; 13*x(1)-41*x(2)2; 14-x(1); x(1)-130; 2-x(2); x(2)-57;% Nonlinear inequality constraintsceq=;Step
4、 3: Invoke constrained optimization routinex0=10,10; % Make a starting guess at the solution options = optimset(LargeScale,off); x, fval = . fmincon(objfun2,x0,confun1,options)运行结果:x = 3.6755 -7.0744fval = 124.14952. min f(x)= s.t. 初选x0=1,1Step 1: Write an M-file objfun3.mfunction f=objfun3(x)f=4*x(
5、1)2+5*x(2)2Step 2: Write an M-file confun3.m for the constraints.function c,ceq=confun3(x)%Nonlinear inequality constraintsc=2*x(1)+3*x(2)-6; -x(1)*x(2)-1;% Nonlinear equality constraintsceq;Step 3: Invoke constrained optimization routinex0=1,1;% Make a starting guess at the solution options = optim
6、set(LargeScale,off); x, fval = . fmincon(objfun,x0,confun,options)运行结果:Optimization terminated: no feasible solution found. Magnitude of search direction less than 2*options.TolX but constraints are not satisfied.x = 1 1fval = -13实例:螺栓连接的优化设计图示为一压气机气缸与缸盖连接的示意图。已知D1=400mm,D2=240mm,缸内工作压力p=8.5Mpa,螺栓材料
7、为45Cr,抗拉强度,屈服强度,拉压疲劳极限,许用疲劳安全系数,取残余预紧力,采用铜皮石棉密封垫片,螺栓相对刚度。从安全、可靠、经济的角度来选择螺栓的个数n和螺栓的直径d。解:1. 目标函数取螺栓组连接经济成本最小为目标。当螺栓的长度、材料和加工条件一定时,螺栓的总成本与n,d值成正比,故本问题优化设计的目标函数为由此可见,设计变量为螺栓个数n和直径d为 2约束条件 (1)强度约束条件:螺栓在脉动载荷下工作,因此螺栓组连接须满足疲劳强度条件其中为应力幅值;为最小应力;为疲劳极限综合影响系数,取=4.4;为应力折算系数,取=0.23.气缸最大载荷螺栓最大工作载荷,螺栓最小工作载荷, 螺栓应力幅值
8、对于普通螺纹,小径,于是疲劳强度约束条件为(2)密封约束条件:考虑密封安全,螺栓间距应小于8d,故密封约束条件为(3)扳手工作空间约束条件:考虑扳手工作空间,螺距间距应大于2d,故扳手工作空间约束条件为(4)非约束条件 螺栓连接的优化数学模型综上所述,本问题的数学模型可表达如下设计变量:目标函数:约束条件:M文件function f=stud_obj(x)f=x(1)*x(2);global p Ksigam psai sigam_1p=8.5*le6;Ksigam=4.4;psai=0.23;sigam_1=330;D2=240;p=1/4*pi*D22*le-6*p;function c,
9、ceq=stud_conl(x)global p Ksigam psai sigam_1p,xF0=(1.6*p+p)/x(1);d1=0.85*x(2);A=1/4*pi*d12;F1=F0-0.8*p/x(1);sigma_max=F0/A;sigma_min=F1/A;sigma_1=(sigma_max-sigma_min)/2;Sa=(2*sigma_1+(Ksigma-psai)*sigma_min)/(Ksigma+psai)*(2*sigma_a+sigma_min);c=1.7-Sa; 400*pi/x(1)-8*x(2); -400*pi/x(1)+2*x(2); 16-x(1); -x(2);ceq=;x0=7,20;x,feval=fmincon(stud_obj,x0,stud_conl)运行结果:x = 16.00 28.84fval = 461.39根据实际问题的意义取整、标准化:n=16,d=30,经验证n和d的取值满足约束条件。