完整版优化设计Matlab编程作业
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
化设计
hl4HU
©0⑥ 3 hlu 凹内r d X1州fci-r
U-
f
F
F
卢F ♦ 忡下¥为+1 —
*— S-ll-« F41:Si —
MATLAB
oftiHMirjirCfiffliiiiJ PHI
■1**■ 温不平?」11,・
—喜M - 〜FT 文词一
时y 片 34ml 3
F
*L9TR0i. Jill!-
LkftLgWf 1S1CSI
掰f 1 ■ >A A A »W I % :k Dnfl w I ■ J k^lXM
prfaMk tjn nn Alflhw
初选 x0=[1,1] 程序:
Step 1: Write an Mfle objfunl.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 routines
x0=[1,1];
>> options = 0Ptimset('LargeScale','off);
>> [x,fval,exitflag,output] = fminunc(@objfun1,x0,options)
运行结果: x =
4.0000 2.0000 fval = -8.0000
exitflag =
1 output = iterations: 3 funcCount: 1
2 stepsize: 1 firstorderopt: 2.3842e-007
algorithm: 'medium-scale: Quasi-Newton line search message: [1x85 char]
非线性有约束优化
1. Min f(x)=3 x : + x 2+2 x 1-3 x 2+5 Subject to:
g 2(x)=5 X 1-3 X 2 -25 < 0 g (x)=13 X -41 X 2 < 0 3 1
2
g 4(x)=14 < X 1 < 130
无约束优化 min f(x)=
X 2 + x 2-2 x 1 x 2-4 x 1
g5 (x)=2 < X 2 < 57
初选x0=[10,10]
Step 1: Write an M-file objfun2.m
function f2=objfun2(x)
f2=3*x(1)人2+x(2)人2+2*x(1)-3*x(2)+5;
Step 2: Write an M-file confunl.m for the constraints. function [c,ceq]=confun1(x) % Nonlinear inequality constraints c=[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 constraints ceq=[];
Step 3: Invoke constrained optimization routine
x0=[10,10]; % Make a starting guess at the solution
>> options = optimset('LargeScale','off);
>> [x, fval]=...
fmincon(@objfun2,x0,[],[],[],[],[],[],@confun1,options)
运行结果:
x =
3.6755 -7.0744 fval =
124.1495
2.min f (x) =4x2 + 5x2
s.t. g 1(x) = 2X] + 3x2- 6 < 0
g (x) = x x +1 > 0
初选x0=[1,1]
Step 1: Write an M-file objfun3.m function f=objfun3(x) f=4*x(1)人2 + 5*x(2)人2
Step 2: Write an M-file confun3.m for the constraints. function [c,ceq]=confun3(x) %Nonlinear inequality constraints c=[2*x(1)+3*x(2)-6;
-x(1)*x(2)-1];
% Nonlinear equality constraints ceq口;
Step 3: Invoke constrained optimization routine
x0=[1,1];% Make a starting guess at the solution
>> options = optimset('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 =
11
fval =
-13
实例:螺栓连接的优化设计
图示为一压气机气缸与缸盖连接的示意图。
已知D1=400mm,D2=240mm,缸内工作压力
p=8.5Mpa,螺栓材料为45Cr,抗拉强度。
b = 1000Mpa,屈服强度。
$ = 320Mpa,拉压
疲劳极限。
=330Mpa,许用疲劳安全系数[S ] = 1.7,取残余预紧力F”= 1.6F,采用-1
a
铜皮石棉密封垫片,螺栓相对刚度K c = 0.8。
从安全、可靠、经济的角度来选择螺栓的个数n和螺栓的直径d。
解:
1.目标函数
取螺栓组连接经济成本C n最小为目标。
当螺栓的长度、材料和加工条件一定时,螺栓的总成本与n,d值成正比,故本问题优化设计的目标函数为
min f (x) = C = nd = x x
由此可见,设计变量为螺栓个数n和直径d为
x = [ n d ] T = [ x x ] T
2.约束条件
(1)强度约束条件:螺栓在脉动载荷下工作,因此螺栓组连接须满足疲劳强度条件
2o +(K -w 4 []
S二才 1 --------- W -- 6 ------ min > S」
及6 +6 i / a
a K +W
其中6 a为应力幅值;6 mi方最小应力;K6为疲劳极限综合影响系数,取K6 =4.4;W 6为应力折算系数,取W6=0.23.
气缸最大载荷P = --D D2p 4 2
P
F
螺栓最大工作载荷F = F … +- , o +
-
n max 1
n d 2
4 i
螺栓最小工作载荷F = F 0-K
『二F o - 0.8p /n ,。
对于普通螺纹,小径d = 0.85d ,于是疲劳强度约束条件为 1
g [
(X )=S ]- S < 0
(2)密封约束条件:考虑密封安全,螺栓间距应小于8d ,故密封约束条件为
f ) n D 0 , 400n o
g \X )=———― 8d = 一 8x
2
n x 2
i
(3)扳手工作空间约束条件:考虑扳手工作空间,螺距间距应大于2d ,故扳手工作空间约 束条件为g
&
)
= 2d 一吗=2x 一料n < 0 3 n 2 x
i
(4)非约束条件
g
(X )=一x < 0, g (X )=一x < 0
螺栓连接的优化数学模型
s .t .g (x )
< 0,u = 1,2,3,4,5 M 文件
function f=stud_obj(x) f=x(1)*x(2); global p Ksigam psai sigam_1 p=8.5*le6;
Ksigam=4.4;psai=0.23;sigam_1=330;D2=240;
螺栓应力幅
值。
——max ------- min
2
min
综上所述, 设计变量: 目标函数:
本问题的数学模型可表达如下 x = l x , x >
约束条件:
p=1/4*pi*D2入2*le-6*p;
function [c,ceq]=stud_conl(x)
global p Ksigam psai sigam_1 p,x
F0=(1.6*p+p)/x(1);
d1=0.85*x(2);
A=1/4*pi*d1A2;
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+sigm a_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.84
fval =
461.39
根据实际问题的意义取整、标准化:n=16, d=30,经验证n和d的取值满足约束条件。