机械优化设计作业—工]+ 2 兀2 —4 * 2x}+3X2< 121 > min f= -4x1-x^x{ -x2 <3x^x2>0在MATLAB下编程如下:* m 肝w|厂1 iLb h鼻「* j-f C L Q rrat VM电+ g ge? thi p irie-f v«irti»mu :»4 l-L 212 3.1 -I]>> b= K. I2;3j ;»= L>:>> [-Kj fv3e 11 £laifj cmtptrl 1 - Lirt t Pg: Cfj Aj bj []>【1, Lbi Opt iviii «Lori 1 a ranijn al Q dL3E =4・ 2Q0D1・ 3000f val ■・oonoex it-"fl a.z ―Iou t put =i■卷e-r -al i ons r 5■^1 g a r 11 t l-|JL £*L N E恵Q—NUEd 口!:X nt iiT L.口If pQHEt"c £it er al 1 atri ■; i: 0" ' C^p't Ji H.L £at 1 □ A t wt BLilialt^idca nc 1 rui a 1 at ion E0<iTiterderapl,: 4.5137e-口Dfln J :0 W Jr〕+ 2X2+ 2乂§ < 722“ min f ——x{x2x3在MATLAB下编程如下:先编写M文件,建立目标函数fun cti on f=zuoye2(x)f=-x(1)*x(2)*x(3);主程序如下:>> x0=[1;1;1];A=[-1,-2 ,-2;1,2,2];b=[0;72];lb=zeros(3,1);[x,fval,exitflag,output]=fmincon('zuoye2',x0,A,b,[],[],lb)Warning: Trust-region-reflective algorithm does not solve this type of problem, using active-setalgorithm. You could also try the interior-point or sqp algorithms: set the Algorithm option to'interior-point' or 'sqp' and rerun. For more help, see Choosing the Algorithm in the documentation.> In fmincon at 472Local minimum possible. Constraints satisfied.fmincon stopped because the predicted change in the objective function is less than the default value of the function tolerance and constraints were satisfied to within the default value of the constraint tolerance.<stopping criteria details>Active inequalities (to within options.TolCon = 1e-006):lower upper ineqlin ineqnonlin2x =23.999712.000112.0001fval =-3.4560e+003exitflag =5output =iterations: 9funcCount: 42Issteple ngth: 1stepsize: 3.3708e-004algorithm: 'medium-scale: SQP, Quasi-Newt on, li ne-search' firstorderopt: 0.0025 con strviolati on: 0message: [1x777 char]3、机床主轴是机床中重要零件之一,一般为多支承空心阶梯轴。
为了便于使用材料力学公式进行结构分析,常将阶梯轴简化成以当量直径表示的尊截面轴。
图1所示的为一根简化的机床主轴芬要求以主轴的自重为目标,对该主轴进行优化设计。
已知条件:主轴材料为45#, 内径d^30mm,外力F=15000I\i许用挠度yo^O.OSmm,材料的弹性模量E=2lOGPa t许用应力[o |=180MPao 30(IW 60W DW110,I、d.氐的量纲均为毫米。
E-EI由题,先选取设计变量。
一、设计变量由于材料已经给定,其质量只是内径d、外径D跨距L及外伸端a的函数。
因此设计变量为(1)二、目标函数依据题意,以主轴自身质量最小为设计目标,即- ⑵P为材料密度。
三、约束条件1) 挠度要求-------- ⑶上式中惯性矩,E为主轴弹性模量。
将I、E代入得:------------- ⑷2) 强度要求------- (5)------------- (6)由(5)(6)式可得:------------ (7)3) 边界约束条件(8)四、将物理模型转化为数学模型(9) S.t.诡3")一心°32F X2X2x t > 300x2 > 60x2 < 110x3 > 90< x3 < 150(10)在MATLAB中先建立目标函数M文件fun cti on f=myfun(x) f=6.16225*(x(1)+x(3))*(x (2) 9-900)/1000000;因为约束为非线性,所以同样建立非线性约束M文件fun cti on [c,ceq]=myc on(x)F=15000;y0=0.05;c(1)=9.71*x(3)A2*(x(1)+x(3))/(x (2)A4-30A4)-1;c(2)=32*F*x (2) *x(3)/(3.14*(x (2)八4-30八4)*180)-1;ceq=[];在MATLAB命令窗口给出初始搜索值和线性约束,并调用优化程序:a=[-1/300 0 00 -1/60 00 1/110 00 0 -1/90]; 注:相比较式( 10 )的约束作了一个变形b=[-1;-1;1;-1];x0=[300;100;100];lb=zeros(3,1); [x,fval,exitflag,output]=fmincon(@myfun,x0,a,b,[],[],lb,[],@mycon) Warning: Trust-region-reflective algorithm does not solve this type of problem, using active-setalgorithm. You could also try the interior-point or sqp algorithms: set the Algorithm option to'interior-point' or 'sqp' and rerun. For more help, see Choosing the Algorithm in the documentation.> In fmincon at 472Local 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 were satisfied to within the default value of the constraint tolerance.<stopping criteria details>Active inequalities (to within options.TolCon = 1e-006):lower upper ineqlin ineqnonlin1 1300.000074.906990.0000 fval =11.3220exitflag = output =iterations: 7 funcCount: 33 Issteple ngth: 1stepsize: 2.9587e-005algorithm: 'medium-scale: SQP, Quasi-Newt on, li ne-search'firstorderopt: 1.1603e-009 co nstrviolatio n: 1.6105e-012message: [1x788 char]经比较可发现和此前的结果一致。
同上,先建立目标函数M 文件fun cti on f=fun(x) f=(x(1)-3F2+x (2)A 2;再建立非线性约束M 文件fun cti on [c,ceq]=f uncon(x)c(1)=x(1)A2+x (2)-4; ceq=[];在MATLAB 命令窗口给出初始搜索值和线性约束,并调用优化程序:>> x0=[1,1];>> a=[-1 0;0 -1] >> b=[-0.5;0] >> lb=zeros(2,1)>> [x,fval,exitflag,output]=fmincon(@fun,x0,a,b,[],[],lb,[],@funcon) <stopping criteria details>Active inequalities (to within options.TolCon = 1e-006): lower upper ineqlin ineqnonlin 2 2 1 x =2.0000 0 fval = 1.0000 exitflag =4smin f = (x t - 3)2 + xj4 一 jtp _ 兀2 — ° st x 2 > 0旺 一 0.5 > 01 output =iterations: 4 funcCount: 16 lssteplength: 1 stepsize: 7.9012e-005 algorithm: 'medium-scale: SQP, Quasi-Newton, line-search' firstorderopt: 7.5958e-007 constrviolation: 6.2446e-009 message: [1x788 char]。