机械优化设计作业.docx
《机械优化设计作业.docx》由会员分享,可在线阅读,更多相关《机械优化设计作业.docx(8页珍藏版)》请在冰点文库上搜索。
机械优化设计作业
在MATLAB下编程如下:
在MATLAB下编程如下:
先编写M文件,建立目标函数
functionf=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-reflectivealgorithmdoesnotsolvethistypeofproblem,usingactive-set
algorithm.Youcouldalsotrytheinterior-pointorsqpalgorithms:
settheAlgorithmoptionto
'interior-point'or'sqp'andrerun.Formorehelp,seeChoosingtheAlgorithminthedocumentation.
>Infminconat472
Localminimumpossible.Constraintssatisfied.
fminconstoppedbecausethepredictedchangeintheobjectivefunction
islessthanthedefaultvalueofthefunctiontoleranceandconstraints
weresatisfiedtowithinthedefaultvalueoftheconstrainttolerance.
Activeinequalities(towithinoptions.TolCon=1e-006):
lowerupperineqlinineqnonlin
2
x=
23.9997
12.0001
12.0001
fval=
-3.4560e+003
exitflag=
5
output=
iterations:
9
funcCount:
42
lssteplength:
1
stepsize:
3.3708e-004
algorithm:
'medium-scale:
SQP,Quasi-Newton,line-search'
firstorderopt:
0.0025
constrviolation:
0
message:
[1x777char]
由题,先选取设计变量。
一、设计变量
由于材料已经给定,其质量只是内径d、外径D、跨距L及外伸端a的函数。
因此设计变量为
X=x1,x2,x2T=l,D,aT
(1)
二、目标函数
依据题意,以主轴自身质量最小为设计目标,即
Fx=14πρx1+x3x22-d2
(2)
ρ为材料密度。
三、约束条件
1)挠度要求
y=Fa2(l+a)3EI≤y0(3)
上式中惯性矩I=π(D4-d4)64,E为主轴弹性模量。
将I、E代
入得:
64Fx32(x1+x3)3πE(x24-d4)≤y0(4)
2)强度要求
σmax=MmaxWz≤[σ](5)
Wz=π(D4-d4)32D(6)
由(5)(6)式可得:
32Fx2x3π(x24-d4)≤[σ](7)
3)边界约束条件
300≤x1≤650,60≤x2≤110,90≤x3≤150(8)
四、将物理模型转化为数学模型
minfx=14πρx1+x3x22-d2(9)
S.t.
(10)
在MATLAB中
先建立目标函数M文件
functionf=myfun(x)
f=6.16225*(x
(1)+x(3))*(x
(2)^2-900)/1000000;
因为约束为非线性,所以同样建立非线性约束M文件
function[c,ceq]=mycon(x)
F=15000;
y0=0.05;
c
(1)=9.71*x(3)^2*(x
(1)+x(3))/(x
(2)^4-30^4)-1;
c
(2)=32*F*x
(2)*x(3)/(3.14*(x
(2)^4-30^4)*180)-1;
ceq=[];
在MATLAB命令窗口给出初始搜索值和线性约束,并调用优化程序:
a=[-1/30000
0-1/600
01/1100
00-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-reflectivealgorithmdoesnotsolvethistypeofproblem,usingactive-set
algorithm.Youcouldalsotrytheinterior-pointorsqpalgorithms:
settheAlgorithmoptionto
'interior-point'or'sqp'andrerun.Formorehelp,seeChoosingtheAlgorithminthedocumentation.
>Infminconat472
Localminimumfoundthatsatisfiestheconstraints.
Optimizationcompletedbecausetheobjectivefunctionisnon-decreasingin
feasibledirections,towithinthedefaultvalueofthefunctiontolerance,
andconstraintsweresatisfiedtowithinthedefaultvalueoftheconstrainttolerance.
Activeinequalities(towithinoptions.TolCon=1e-006):
lowerupperineqlinineqnonlin
11
4
x=
300.0000
74.9069
90.0000
fval=
11.3220
exitflag=
1
output=
iterations:
7
funcCount:
33
lssteplength:
1
stepsize:
2.9587e-005
algorithm:
'medium-scale:
SQP,Quasi-Newton,line-search'
firstorderopt:
1.1603e-009
constrviolation:
1.6105e-012
message:
[1x788char]
经比较可发现和此前的结果一致。
同上,先建立目标函数M文件
functionf=fun(x)
f=(x
(1)-3)^2+x
(2)^2;
再建立非线性约束M文件
function[c,ceq]=funcon(x)
c
(1)=x
(1)^2+x
(2)-4;
ceq=[];
在MATLAB命令窗口给出初始搜索值和线性约束,并调用优化程序:
>>x0=[1,1];
>>a=[-10;0-1]
>>b=[-0.5;0]
>>lb=zeros(2,1)
>>[x,fval,exitflag,output]=fmincon(@fun,x0,a,b,[],[],lb,[],@funcon)
Activeinequalities(towithinoptions.TolCon=1e-006):
lowerupperineqlinineqnonlin
221
x=
2.00000
fval=
1.0000
exitflag=
1
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:
[1x788char]