基于Matlab的优化设计
许文祥 072093 20091003791
一. 无约束优化
题目:求 min f(x)=x(1)^2+x(2)^2-x(1)*x(2)-10*x(1)-4*x(2);
x0=[1,1];
M文件的编写:
function f=wen(x)
f=-10*x(1)-4*x(2)-x(1)*x(2)+x(1)^2+x(2)^2;
matlab输入:
>> x0=[1,1];
>> [x,fval]=fminunc(@wen,x0)
运行结果:
x =
8.0000 6.0000
fval =
-52.0000
二.有约束优化
题目:如图所示为一对两杆支架,在支架的顶点承受一个载荷为2F=300000N,支架之间的水平距离为2B=1520mm,若已选定壁厚T=2.5mm钢管,密度ρ=7.8*10^(-6)kg/mm3,屈服极限为700Mpa,试在满足强度条件下设计最轻的支架尺寸。
设计变量:x=[x(1),x(2)];
目标函数:f(x)=7.8*10^(-6)*x(2)*(2.5*pi*x(1)-6.25*pi);
约束条件:
c(1)=150000/(A*cosØ)=150000*x(2)/((sqrt((x(2))^2-760^2))*(2.5*pi*x(1)-6.25*pi)))-700<=0;
c(2)=6.25*pi-2.5*pi*x(1)<=0;
c(3)=-x(1)<=0;
c(4)=-x(2)<=0;
M文件的编写:
function [c,ceq]=qin(x)
c(1)=150000*x(2)./((sqrt((x(2))^2-760^2)*(2.5*pi*x(1)-6.25*pi)))-700;
c(2)=6.25*pi-2.5*pi*x(1);
ceq=[];
matlab输入:
>> fun='7.8*x(2)*(2.5*pi*x(1)-6.25*pi)/1000000';
>> x0=[100,3000];
>> A=[-1,0;0,-1];
>> b=[0;0];
>> Aeq=[];
>> beq=[];
>> lb=[6;760];
>> ub=[1000;100000];
>> options=optimset('display','iter');
>> [x,fval]=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,@qin,options)
运行结果:
> In qin at 2
In optim\\private\\nlconst at 789
In fmincon at 498
11 48 3.32968 21.9 0.5 1.68 Hessian modified
> In qin at 2
-3.8
In optim\\private\\nlconst at 789
In fmincon at 498
12 53 2.50993 52.4 0.5 -1.79 0.755
13 0.41
14 0.0219
15 0.00359 16 0.00136 17 1.62e-005 18 1.07e-006 19 58 2.31455 62 2.52635 66 2.53776 70 2.53923 74 2.54056
78 2.54057 Hessian modified
82 2.54057 68.43 5.447 0.974 0.3737 0.004385 1.293e-005 8.375e-009 0.5 -0.503 1 0.216 1 0.00997 1 0.000983 1 0.00133 1 1.58e-005 1 4.69e-008
4.17e-009 Hessian modified
Optimization terminated: first-order optimality measure less
than options.TolFun and maximum constraint violation is less
than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1
x =
1.0e+003 *
0.0411 1.0748
fval =
2.5406
结论:由上面的结果可知,当x(1)=41.4mm,x(2)=1074.8mm时,可以得到满足条件下单根的最轻值为M0=2.5406kg,总质量为M=2.5406*2=5.0812kg。
因篇幅问题不能全部显示,请点此查看更多更全内容