
http://www.ma-xy.com
1.2 超薄座椅的优化设计 第一章 超薄座椅
6 % %
7 h1 = x(1 ) ; h2 = x( 2 ) ;
8 % 输 入 插 值 点 坐 标
9 x = [ 0 , 5 0 ,7 5 ,11 0 ,19 0 ,21 0 ,25 0 ,33 0 ,40 0 ,50 0 ,53 0 ,550 ,610 ,670 ,705 ,750 ,847 ] ;
10 y = [ 1 4 , 10 , 5 , 4 .4 , 1 0 , 14. 5 , 1 7. 8 , h1 , 13 . 6 , 7. 2 , 4 , 5 . 2 , h2 , 8 , 1 0 , 8 . 5 , 5 . 6 ] ;
11 pp = csape (x , y , ’ not−a−knot ’ ) ;
12 point1 = 240; point2 = 570;%有 曲 率 约 束 的 点: 1000 , 500腰 椎 和 肩 胛 骨
13 % 找 到 约 束 点 的 位 置
14 ind1 = sum(x<=point1 ) ; ind2 = sum(x<=point2 ) ;
15 % 计 算 约 束 点 的 曲 率
16 f1 =@(x1 ) pp . c oe f s ( ind1 , 1 ) *(x1−x( ind1 ) ) .^1+pp . c o ef s ( ind1 , 2 ) *(x1−x ( ind1 ) ) .^2+pp . c oe f s
( ind1 , 3) *(x1−x ( ind1 ) ).^3+pp . c oe fs ( ind1 , 4) ;
17 f f 1 =@( x1 ) pp . c oe f s ( ind1 , 1 ) *(x1−x( ind1 ) ) .^1+pp . c o ef s ( ind1 , 2 ) *(x1−x ( ind1 ) ).^2+pp . c oe f s
( ind1 , 3) *(x1−x ( ind1 ) ).^3+pp . c oe fs ( ind1 , 4) ;
18 f2 =@(x2 ) pp . c oe f s ( ind2 , 1 ) *(x2−x( ind2 ) ) .^1+pp . c o ef s ( ind2 , 2 ) *(x2−x ( ind2 ) ) .^2+pp . c oe f s
( ind2 , 3) *(x2−x ( ind2 ) ).^3+pp . c oe fs ( ind2 , 4) ;
19 f f 2 =@( x2 ) pp . c oe f s ( ind2 , 1 ) *(x2−x( ind2 ) ) .^1+pp . c o ef s ( ind2 , 2 ) *(x2−x ( ind2 ) ).^2+pp . c oe f s
( ind2 , 3) *(x2−x ( ind2 ) ).^3+pp . c oe fs ( ind2 , 4) ;
20 syms x1 x2 % 通 过 符 号 变 量 将 匿 名 函 数 转 换 为 符 号 函 数
21 y1 = f 1 ( x1 ) ; yy1 = f f 1 ( x1 ) ; y2 = f 2 ( x2 ) ; yy2 = f f 2 ( x2 ) ;% 符 号 函 数 , 可 求 导
22 g1 = matlabFunction ( d i f f ( y1 ) ) ;% 通 过 matlabFunction 将 符 号 函 数 转 换 为 匿 名 函 数
23 gg1 = matlabFunction ( d i f f ( yy1 ) ) ;
24 g2 = matlabFunction ( d i f f ( y2 ) ) ;
25 gg2 = matlabFunction ( d i f f ( yy2 ) ) ;
26 R1 = ((1+g1 ( point1 ) ^2) ^(3/2) ) /abs ( gg1 ( point1 ) ) ;
27 R2 = ((1+g2 ( point2 ) ^2) ^(3/2) ) /abs ( gg2 ( point2 ) ) ;
28 ObjV = (R1−1000)^2+(R2− 500) ^ 2 ;
29
GA 求解程序如下
1 % 设 脊 椎 曲 线 为 分 段 三 次 样 条 函 数 , 且 在 腰 椎 和 肩 胛 骨 的 曲 率 为 1000 和 500
2 clc , c le ar
3 lbx =5; ubx=20; %函 数 自 变 量 x( 腰 凸 ) 范 围
4 lby =5; uby=15; %函 数 自 变 量 y( 颈 椎 凸 ) 范 围
5 fun = @(x) o b jfunct i o n (x ) ;
6 A = [ ] ; b = [ ] ;
7 Aeq = [ ] ; beq = [ ] ;
8 l b = [ lbx , lby ] ;
9 ub = [ ubx , uby ] ;
10 nonlcon = [ ] ;
11 nvars = 2;
12 o p t i o n s = gaoptimset ( ’ Popu lationSize ’ ,100 , ’ Cros soverFraction ’ , 0 .7 5 , ’ Generations ’ , 2 0 , ’
StallGenLimit ’ , 4 0 , ’ PlotFcns ’ ,{ @gaplotbestf , @gaplotb estindiv }) ; %参 数 设 置
13 besth = ga ( fun , nvars ,A, b , Aeq , beq , lb , ub , nonlcon , options ) ;
14
GA 进化图/迭代图如图 (1.1) 所示
http://www.ma-xy.com 4 http://www.ma-xy.com