# 有约束最优化问题 matlab,请教一个Matlab关于有约束最优化问题

function newfinger

clc;clear;

x0=[30,30,0,0,25,0,5,5,0,0,0,0,0,0,10,50,10,10,30,10,5,5,5];

lb=[30,30,0,0,25,0,5,5,0,0,0,0,0,0,10,50,10,10,30,10,5,5,5];

ub=[126,92,101,101,125,101,30,30,pi/2,pi/2,pi/2,pi/2,pi/2,pi/2,80,70,40,40,70,40,30,30,100];

options = optimset('Algorithm','active-set');

[x,f]=fmincon(@fingerobjfunc,x0,[],[],[],[],lb,ub,@fingernlconstr,options)

smallestmoment=f

function[C,Ceq]=fingernlconstr(x)

s0=x(1);y0=x(2);s1=x(3);y1=x(4);s2=x(5);y2=x(6);f1=x(7);f2=x(8);c1=x(9);c2=x(10);c3=(11);c4=x(12);c5=x(13);c6=x(14);s3=x(15);y3=x(16);s4=x(17);y4=x(18);s5=x(19);y5=x(20);f3=x(21);f4=x(22);f5=x(23);

C(1)=30-abs(y0-s0*atan(c1))/sqrt(1+atan(c1)^2);                                         %C(1)-C(6)为几何条件的约束，表示球心到关节板直线的距离大于30；

C(2)=30-abs(y0-atan(c1+c2)*(s0-46*sin(c1))-46*cos(c1))/sqrt(1+atan(c1+c2)^2);

C(3)=30-abs(y0-atan(c1+c2+c3)*(s0-46*sin(c1)-34*sin(c1+c2))-46*cos(c1)-34*cos(c1+c2))/sqrt(1+atan(c1+c2+c3)^2);

C(4)=30-abs(y0-s0*tan(c4)+25*tan(c4))/sqrt(1+tan(c4)^2);

C(5)=30-abs(y0-tan(c4+c5)*(s0-25-46*cos(c4))-46*sin(c4))/sqrt(1+tan(c4+c5)^2);

C(6)=30-abs(y0-tan(c4+c5+c6)*(s0-46*cos(c4)-34*cos(c4+c5)-25)-46*sin(c4)-34*sin(c4+c5))/sqrt(1+tan(c4+c5+c6)^2);

C(7)=(s1-46*sin(c1)-34.5*sin(c1+c2))^2+(y1-46*cos(c1)-34.5*cos(c1+c2))^2-21^2;      %C(7)-C(11)表示接触点在指节长度范围内

C(8)=(s2-25-46*cos(c4)-34*cos(c4+c5))^2+(y2-46*sin(c4)-34*sin(c4+c5))^2-21^2;

C(9)=(s3-25-46*cos(c4)-34*cos(c4+c5))^2+(y3-46*sin(c4)-34*sin(c4+c5))^2-28^2;

C(10)=(s4-46*sin(c1))^2+(y4-46*cos(c1))^2-40^2;

C(11)=(s5-25)^2+(y4)^2-40^2;

C(12)=30-0.3*(f1+f2+f3+f4+f5);

C(13)=s1-s0;   %保证接触点在圆柱的各半平面内

C(14)=s0-s2;

C(15)=s3-s0;

C(16)=s4-s0;

C(17)=s0-s5;

Ceq(1)=y1-atan(c1+c2+c3)*(s1-46*sin(c1)-34*sin(c1+c2))-46*cos(c1)-34*cos(c1+c2);    %几何条件的线性等式约束，表示接触点在指节板所在直线及园曲线方程上

Ceq(2)=(s1-s0)^2+(y1-y0)^2-900;

Ceq(3)=y2-tan(c4+c5+c6)*(s2-25-46*cos(c4)-34*cos(c4+c5))-46*sin(c4)-34*sin(c4+c5);

Ceq(4)=(s2-s0)^2+(y2-y0)^2-900;

Ceq(5)=f1*sin(c1+c2+c3)+f3*sin(c1+c2)+f4*sin(c1)-f2*sin(c4+c5+c6)-f5*sin(c4);       %%修改力平衡方程式

Ceq(6)=f1*cos(c1+c2+c3)+f3*cos(c1+c2)-f4*cos(c1)+f2*cos(c4+c5+c6)+f5*cos(c4);       %%修改力平衡方程式

Ceq(7)=y3-atan(c1+c2)*(s3-46*sin(c1))-46*cos(c1);                      %接触点在指节及圆柱的平面曲线上

Ceq(8)=(s3-s0)^2+(y3-y0)^2-900;

Ceq(9)=y4-atan(c1)*s4;

Ceq(10)=(s4-s0)^2+(y4-y0)^2-900;

Ceq(11)=y5-atan(c4)*(s5-25);

Ceq(12)=(s5-s0)^2+(y5-y0)^2-900;

function f=fingerobjfunc(x)

s0=x(1);y0=x(2);s1=x(3);y1=x(4);s2=x(5);y2=x(6);f1=x(7);f2=x(8);c1=x(9);c2=x(10);c3=(11);c4=x(12);c5=x(13);c6=x(14);s3=x(15);y3=x(16);s4=x(17);y4=x(18);s5=x(19);y5=x(20);f3=x(21);f4=x(22);f5=x(23);

f=4*900/(900-(f1*(46*cos(c2+c3)+34*cos(c3)+sqrt((s1-46*sin(c1)-34*sin(c1+c2))^2+(y1-46*cos(c1)-34.5*cos(c1+c2))^2))+f4*sqrt((s4-46*sin(c1))^2+(y4-46*cos(c1))^2)+f3*(46*cos(c2)+sqrt((s3-46*sin(c1))^2+(y3-46*cos(c1))^2)))^2)+...

4*900/(900-(f1*(34.5*cos(c3)+sqrt((s1-46*sin(c1)-34*sin(c1+c2))^2+(y1-46*cos(c1)-34.5*cos(c1+c2))^2))+f3*sqrt((s3-46*sin(c1))^2+(y3-46*cos(c1))^2))^2)+...

4*900/(900-(f1*sqrt((s1-46*sin(c1)-34*sin(c1+c2))^2+(y1-46*cos(c1)-34.5*cos(c1+c2))^2))^2)+...

4*900/(900-(f2*(46*cos(c4+c5)+34*cos(c6)+sqrt((s2-25-46*cos(c4)-34*cos(c4+c5))^2+(y2-46*sin(c4)-34*sin(c4+c5))^2))+f5*sqrt((s5-25)^2+(y5)^2))^2)+...

4*900/(900-(f2*(34.5*cos(c6)+sqrt((s2-25-46*cos(c4)-34*cos(c4+c5))^2+(y2-46*sin(c4)-34*sin(c4+c5))^2)))^2)+...

4*900/(900-(f2*sqrt((s2-46*cos(c4)-34*cos(c4+c5))^2+(y2--46*sin(c4)-34.5*sin(c4+c5))^2))^2);

x =

Columns 1 through 12

39.2281   53.1696   19.8605   85.7515   69.5218   49.9037   23.8427   31.2546    0.6226   -1.3253   -0.0000    1.7621

Columns 13 through 23

-1.0085   -1.3253    9.1429   48.6747   41.1023   23.2256   47.6912   24.2121   20.0389   31.3253    4.0050

f =

-0.0202

smallestmoment =

-0.0202

[本帖最后由 maver 于 2009-5-26 15:12 编辑]

• 0
点赞
• 0
收藏
• 0
评论
04-27
10-13 574
10-11 98
04-13 539
03-21 1万+
07-08 2767
05-14
03-17 1000
04-11 9836

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助