原子距离问题.docx
《原子距离问题.docx》由会员分享,可在线阅读,更多相关《原子距离问题.docx(22页珍藏版)》请在冰豆网上搜索。
![原子距离问题.docx](https://file1.bdocx.com/fileroot1/2023-4/17/7d0fadf0-beb5-4730-9b00-f3127c216533/7d0fadf0-beb5-4730-9b00-f3127c2165331.gif)
原子距离问题
实验7无约束优化
题目5
某分子由25个原子组成,并且已经通过实验测量得到了其中某些原子对之间的距离(假设在平面结构上讨论),如表所示。
请你确定每个原子的位置关系。
表
原子对
距离
原子对
距离
原子对
距离
原子对
距离
(4,1)
(5,4)
(18,8)
(15,13)
(12,1)
(12,4)
(13,9)
(19,13)
(13,1)
(24,4)
(15,9)
(15,14)
(17,1)
(8,6)
(22,9)
(16,14)
(21,1)
(13,6)
(11,10)
(20,16)
(5,2)
(19,6)
(13,10)
(23,16)
(16,2)
(25,6)
(19,10)
(18,17)
(17,2)
(8,7)
(20,10)
(19,17)
(25,2)
(14,7)
(22,10)
(20,19)
(5,3)
(16,7)
(18,11)
(23,19)
(20,3)
(20,7)
(25,11)
(24,19)
(21,3)
(21,7)
(15,12)
(23,21)
(24,3)
(14,8)
(17,12)
(23,22)
【模型建立】
设第i个点所在的位置为
,因为所求的是各原子间的位置关系,可以设定第一个点坐标为,然后再计算其他原子的位置
,使它在最大程度上满足上表中提供的数据,即让
达到最小,其中
表示第i个原子和第j个原子之间的距离,数据如上表中所示。
问题转化为无约束优化:
【算法设计】
上面是一个无约束优化问题,要求
可以归结到无约束规划模型minf(x),令X=[0,X2,X3,X4,……,x25,0,y2,y3,……,y25],调用基本命令fminunc来做,也可以令,调用lsqnonlin命令来做。
【程序】
方法一用lsqnonlin命令实现
functionf=distance(x,d)
f
(1)=(x(1,3))^2+(x(2,3))^2-d
(1)^2;%对应条件第4个和第1个原子间距
f
(2)=(x(1,11))^2+(x(2,11))^2-d
(2)^2;
f(3)=(x(1,12))^2+(x(2,12))^2-d(3)^2;
f(4)=(x(1,16))^2+(x(2,16))^2-d(4)^2;
f(5)=(x(1,20))^2+(x(2,20))^2-d(5)^2;
f(6)=(x(1,4)-x(1,1))^2+(x(2,4)-x(2,1))^2-d(6)^2;
f(7)=(x(1,15)-x(1,1))^2+(x(2,15)-x(2,1))^2-d(7)^2;
f(8)=(x(1,16)-x(1,1))^2+(x(2,16)-x(2,1))^2-d(8)^2;
f(9)=(x(1,24)-x(1,1))^2+(x(2,24)-x(2,1))^2-d(9)^2;
f(10)=(x(1,4)-x(1,2))^2+(x(2,4)-x(2,2))^2-d(10)^2;
f(11)=(x(1,19)-x(1,2))^2+(x(2,19)-x(2,2))^2-d(11)^2;
f(12)=(x(1,20)-x(1,2))^2+(x(2,20)-x(2,2))^2-d(12)^2;
f(13)=(x(1,23)-x(1,2))^2+(x(2,23)-x(2,2))^2-d(13)^2;
f(14)=(x(1,4)-x(1,3))^2+(x(2,4)-x(2,3))^2-d(14)^2;
f(15)=(x(1,11)-x(1,3))^2+(x(2,11)-x(2,3))^2-d(15)^2;
f(16)=(x(1,23)-x(1,3))^2+(x(2,23)-x(2,3))^2-d(16)^2;
f(17)=(x(1,7)-x(1,5))^2+(x(2,7)-x(2,5))^2-d(17)^2;
f(18)=(x(1,12)-x(1,5))^2+(x(2,12)-x(2,5))^2-d(18)^2;
f(19)=(x(1,18)-x(1,5))^2+(x(2,18)-x(2,5))^2-d(19)^2;
f(20)=(x(1,24)-x(1,5))^2+(x(2,24)-x(2,5))^2-d(20)^2;
f(21)=(x(1,7)-x(1,6))^2+(x(2,7)-x(2,6))^2-d(21)^2;
f(22)=(x(1,13)-x(1,6))^2+(x(2,13)-x(2,6))^2-d(22)^2;
f(23)=(x(1,15)-x(1,6))^2+(x(2,15)-x(2,6))^2-d(23)^2;
f(24)=(x(1,19)-x(1,6))^2+(x(2,19)-x(2,6))^2-d(24)^2;
f(25)=(x(1,20)-x(1,6))^2+(x(2,20)-x(2,6))^2-d(25)^2;
f(26)=(x(1,13)-x(1,7))^2+(x(2,13)-x(2,7))^2-d(26)^2;
f(27)=(x(1,17)-x(1,7))^2+(x(2,17)-x(2,7))^2-d(27)^2;
f(28)=(x(1,12)-x(1,8))^2+(x(2,12)-x(2,8))^2-d(28)^2;
f(29)=(x(1,14)-x(1,8))^2+(x(2,14)-x(2,8))^2-d(29)^2;
f(30)=(x(1,21)-x(1,8))^2+(x(2,21)-x(2,8))^2-d(30)^2;
f(31)=(x(1,10)-x(1,9))^2+(x(2,10)-x(2,9))^2-d(31)^2;
f(32)=(x(1,12)-x(1,9))^2+(x(2,12)-x(2,9))^2-d(32)^2;
f(33)=(x(1,18)-x(1,9))^2+(x(2,18)-x(2,9))^2-d(33)^2;
f(34)=(x(1,19)-x(1,9))^2+(x(2,19)-x(2,9))^2-d(34)^2;
f(35)=(x(1,21)-x(1,9))^2+(x(2,21)-x(2,9))^2-d(35)^2;
f(36)=(x(1,17)-x(1,10))^2+(x(2,17)-x(2,10))^2-d(36)^2;
f(37)=(x(1,24)-x(1,10))^2+(x(2,24)-x(2,10))^2-d(37)^2;
f(38)=(x(1,14)-x(1,11))^2+(x(2,14)-x(2,11))^2-d(38)^2;
f(39)=(x(1,16)-x(1,11))^2+(x(2,16)-x(2,11))^2-d(39)^2;
f(40)=(x(1,14)-x(1,12))^2+(x(2,14)-x(2,12))^2-d(40)^2;
f(41)=(x(1,18)-x(1,12))^2+(x(2,18)-x(2,12))^2-d(41)^2;
f(42)=(x(1,14)-x(1,13))^2+(x(2,14)-x(2,13))^2-d(42)^2;
f(43)=(x(1,15)-x(1,13))^2+(x(2,15)-x(2,13))^2-d(43)^2;
f(44)=(x(1,19)-x(1,15))^2+(x(2,19)-x(2,15))^2-d(44)^2;
f(45)=(x(1,22)-x(1,15))^2+(x(2,22)-x(2,15))^2-d(45)^2;
f(46)=(x(1,17)-x(1,16))^2+(x(2,17)-x(2,16))^2-d(46)^2;
f(47)=(x(1,18)-x(1,16))^2+(x(2,18)-x(2,16))^2-d(47)^2;
f(48)=(x(1,19)-x(1,18))^2+(x(2,19)-x(2,18))^2-d(48)^2;
f(49)=(x(1,22)-x(1,18))^2+(x(2,22)-x(2,18))^2-d(49)^2;
f(50)=(x(1,23)-x(1,18))^2+(x(2,23)-x(2,18))^2-d(50)^2;
f(51)=(x(1,22)-x(1,20))^2+(x(2,22)-x(2,20))^2-d(51)^2;
f(52)=(x(1,22)-x(1,21))^2+(x(2,22)-x(2,21))^2-d(52)^2;
clearall
x0=[zeros(1,24);ones(1,24)];
d=[,,,,,,,,,...
,,,,,,,,...
,,,,,,,,...
,,,,,,,,...
,,,,,,,,...
,,,,,]';%设定初值
[x,norms]=lsqnonlin(@distance,x0,[],[],[],d);
p=x';%p第一行即为第二个原子的横、纵坐标;p第二行为第三个原子的横、纵坐标……
a=[0,x(1,:
)];
b=[0,x(2,:
)];
plot(a,b,'*');%画散点图表示出原子的位置
【输出结果】
每个原子的位置如下(即第二个原子的位置为(,),第三个原子为(1,6142,1,。
1211),……):
p=
为了形象直观地表示出各点的位置,画出如下的散点图:
方法二用fminunc实现
functionf=distance1(x,d)
f=(x(1,3))^2+(x(2,3))^2-d
(1)^2;
f=f+(x(1,11))^2+(x(2,11))^2-d
(2)^2;
f=f+(x(1,12))^2+(x(2,12))^2-d(3)^2;
f=f+(x(1,16))^2+(x(2,16))^2-d(4)^2;
f=f+(x(1,20))^2+(x(2,20))^2-d(5)^2;
f=f+(x(1,4)-x(1,1))^2+(x(2*5-2)-x(2,1))^2-d(6)^2;
f=f+(x(1,15)-x(1,1))^2+(x(2,15)-x(2,1))^2-d(7)^2;
f=f+(x(1,16)-x(1,1))^2+(x(2,16)-x(2,1))^2-d(8)^2;
f=f+(x(1,24)-x(1,1))^2+(x(2,24)-x(2,1))^2-d(9)^2;
f=f+(x(1,4)-x(1,2))^2+(x(2,4)-x(2,2))^2-d(10)^2;
f=f+(x(1,19)-x(1,2))^2+(x(2,19)-x(2,2))^2-d(11)^2;
f=f+(x(1,20)-x(1,2))^2+(x(2,20)-x(2,2))^2-d(12)^2;
f=f+(x(1,23)-x(1,2))^2+(x(2,23)-x(2,2))^2-d(13)^2;
f=f+(x(1,4)-x(1,3))^2+(x(2,4)-x(2,3))^2-d(14)^2;
f=f+(x(1,11)-x(1,3))^2+(x(2,11)-x(2,3))^2-d(15)^2;
f=f+(x(1,23)-x(1,3))^2+(x(2,23)-x(2,3))^2-d(16)^2;
f=f+(x(1,7)-x(1,5))^2+(x(2,7)-x(2,5))^2-d(17)^2;
f=f+(x(1,12)-x(1,5))^2+(x(2,12)-x(2,5))^2-d(18)^2;
f=f+(x(1,18)-x(1,5))^2+(x(2,18)-x(2,5))^2-d(19)^2;
f=f+(x(1,24)-x(1,5))^2+(x(2,24)-x(2,5))^2-d(20)^2;
f=f+(x(1,7)-x(1,6))^2+(x(2,7)-x(2,6))^2-d(21)^2;
f=f+(x(1,13)-x(1,6))^2+(x(2,13)-x(2,6))^2-d(22)^2;
f=f+(x(1,15)-x(1,6))^2+(x(2,15)-x(2,6))^2-d(23)^2;
f=f+(x(1,19)-x(1,6))^2+(x(2,19)-x(2,6))^2-d(24)^2;
f=f+(x(1,20)-x(1,6))^2+(x(2,20)-x(2,6))^2-d(25)^2;
f=f+(x(1,13)-x(1,7))^2+(x(2,13)-x(2,7))^2-d(26)^2;
f=f+(x(1,17)-x(1,7))^2+(x(2,17)-x(2,7))^2-d(27)^2;
f=f+(x(1,12)-x(1,8))^2+(x(2,12)-x(2,8))^2-d(28)^2;
f=f+(x(1,14)-x(1,8))^2+(x(2,14)-x(2,8))^2-d(29)^2;
f=f+(x(1,21)-x(1,8))^2+(x(2,21)-x(2,8))^2-d(30)^2;
f=f+(x(1,10)-x(1,9))^2+(x(2,10)-x(2,9))^2-d(31)^2;
f=f+(x(1,12)-x(1,9))^2+(x(2,12)-x(2,9))^2-d(32)^2;
f=f+(x(1,18)-x(1,9))^2+(x(2,18)-x(2,9))^2-d(33)^2;
f=f+(x(1,19)-x(1,9))^2+(x(2,19)-x(2,9))^2-d(34)^2;
f=f+(x(1,21)-x(1,9))^2+(x(2,21)-x(2,9))^2-d(35)^2;
f=f+(x(1,17)-x(1,10))^2+(x(2,17)-x(2,10))^2-d(36)^2;
f=f+(x(1,24)-x(1,10))^2+(x(2,24)-x(2,10))^2-d(37)^2;
f=f+(x(1,14)-x(1,11))^2+(x(2,14)-x(2,11))^2-d(38)^2;
f=f+(x(1,16)-x(1,11))^2+(x(2,16)-x(2,11))^2-d(39)^2;
f=f+(x(1,14)-x(1,12))^2+(x(2,14)-x(2,12))^2-d(40)^2;
f=f+(x(1,18)-x(1,12))^2+(x(2,18)-x(2,12))^2-d(41)^2;
f=f+(x(1,14)-x(1,13))^2+(x(2,14)-x(2,13))^2-d(42)^2;
f=f+(x(1,15)-x(1,13))^2+(x(2,15)-x(2,13))^2-d(43)^2;
f=f+(x(1,19)-x(1,15))^2+(x(2,19)-x(2,15))^2-d(44)^2;
f=f+(x(1,22)-x(1,15))^2+(x(2,22)-x(2,15))^2-d(45)^2;
f=f+(x(1,17)-x(1,16))^2+(x(2,17)-x(2,16))^2-d(46)^2;
f=f+(x(1,18)-x(1,16))^2+(x(2,18)-x(2,16))^2-d(47)^2;
f=f+(x(1,19)-x(1,18))^2+(x(2,19)-x(2,18))^2-d(48)^2;
f=f+(x(1,22)-x(1,18))^2+(x(2,22)-x(2,18))^2-d(49)^2;
f=f+(x(1,23)-x(1,18))^2+(x(2,23)-x(2,18))^2-d(50)^2;
f=f+(x(1,22)-x(1,20))^2+(x(2,22)-x(2,20))^2-d(51)^2;
f=f+(x(1,22)-x(1,21))^2+(x(2,22)-x(2,21))^2-d(52)^2;
clearall;
d=[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]';
x0=[zeros(1,26),ones(1,24)];
opt=optimset('tolx',1e-16,'tolf',1e-16);
[x,z,exit1,out1]=fminunc(@distance1,x0,opt,d);
p=[0,0;x(1:
24)',x(25:
48)'];
a=[0,x(1:
24)];
b=[0,x(25:
48)];
plot(a,b,'*');%画散点图表示原子位置
【输出结果】
每个原子的位置如下(即第二个原子的位置为(,),第二个原子为(,),……):
p=
00
画出位置散点图如下:
【结果分析】
(1)关于lsqononlin与fminunc精确性的探讨
用上面两种不同的命令所求出来的结果并不一样,可能是因为模型建立稍有差别导致算法不同而引起的。
为了找到更适合解决本题的模型,在命令窗口中输入以下命令比较两种算法的精确性。
对于方法一(用lsqnonlin命令实现)
>>d=[,,,,,,,,,...
,,,,,,,,...
,,,,,,,,...
,,,,,,,,...
,,,,,,,,...
,,,,,]';
x=p';
f
(1)=(x(1,3))^2+(x(2,3))^2-d
(1)^2;%对应条件第4个和第1个原子间距
f
(2)=(x(1,11))^2+(x(2,11))^2-d
(2)^2;
f(3)=(x(1,12))^2+(x(2,12))^2-d(3)^2;
f(4)=(x(1,16))^2+(x(2,16))^2-d(4)^2;
f(5)=(x(1,20))^2+(x(2,20))^2-d(5)^2;
f(6)=(x(1,4)-x(1,1))^2+(x(2*5-2)-x(2,1))^2-d(6)^2;
f(7)=(x(1,15)-x(1,1))^2+(x(2,15)-x(2,1))^2-d(7)^2;
f(8)=(x(1,16)-x(1,1))^2+(x(2,16)-x(2,1))^2-d(8)^2;
f(9)=(x(1,24)-x(1,1))^2+(x(2,24)-x(2,1))^2-d(9)^2;
f(10)=(x(1,4)-x(1,2))^2+(x(2,4)-x(2,2))^2-d(10)^2;
f(11)=(x(1,19)-x(1,2))^2+(x(2,19)-x(2,2))^2-d(11)^2;
f(12)=(x(1,20)-x(1,2))^2+(x(2,20)-x(2,2))^2-d(12)^2;
f(13)=(x(1,23)-x(1,2))^2+(x(2,23)-x(2,2))^2-d(13)^2;
f(14)=(x(1,4)-x(1,3))^2+(x(2,4)-x(2,3))^2-d(14)^2;
f(15)=(x(1,11)-x(1,3))^2+(x(2,11)-x(2,3))^2-d(15)^2;
f(16)=(x(1,23)-x(1,3))^2+(x(2,23)-x(2,3))^2-d(16)^2;
f(17)=(x(1,7)-x(1,5))^2+(x(2,7)-x(2,5))^2-d(17)^2;
f(18)=(x(1,12)-x(1,5))^2+(x(2,12)-x(2,5))^2-d(18)^2;
f(19)=(x(1,18)-x(1,5))^2+(x(2,18)-x(2,5))^2-d(19)^2;
f(20)=(x(1,24)-x(1,5))^2+(x(2,24)-x(2,5))^2-d(20)^2;
f(21)=(x(1,7)-x(1,6))^2+(x(2,7)-x(2,6))^2-d(21)^2;
f(22)=(x(1,13)-x(1,6))^2+(x(2,13)-x(2,6))^2-d(22)^2;
f(23)=(x(1,15)-x(1,6))^2+(x(2,15)-x(2,6))^2-d(23)^2;
f(24)=(x(1,19)-x(1,6))^2+(x(2,19)-x(2,6))^2-d(24)^2;
f(25)=(x(1,20)-x(1,6))^2+(x(2,20)-x(2,6))^2-d(25)^2;
f(26)=(x(1,13)-x(1,7))^2+(x(2,13)-x(2,7))^2-d(26)^2;
f(27)=(x(1,17)-x(1,7))^2+(x(2,17)-x(2,7))^2-d(27)^2;
f(28)=(x(1,12)-x(1,8))^2+(x(2,12)-x(2,8))^2-d(28)^2;
f(29)=(x(1,14)-x(1,8))^2+(x(2,14)-x(2,8))^2-d(29)^2;
f(30)=(x(1,21)-x(1,8))^2+(x(2,21)-x(2,8))^2-d(30)^2;
f(31)=(x(1,10)-x(1,9))^2+(x(2,10)-x(2,9))^2-d(31)^2;
f(32)=(x(1,12)-x(1,9))^2+(x(2,12)-x(2,9))^2-d(32)^2;
f(33)=(x(1,18)-x(1,9))^2+(x(2,18)-x(2,9))^2-d(33)^2;
f(34)=(x(1,19)-x(1,9))^2+(x(2,19)-x(2,9))^2-d(34)^2;
f(35)=(x(1,21)-x(1,9))^2+(x(2,21)-x(2,9))^2-d(35)^2;
f(36)=(x(1,17)-x(1,10))^2+(x(2,17)-x(2,10))^2-d(36)^2;
f(37)=(x(1,24)-x(1,10))^2+(x(2,24)-x(2,10))^2-d(37)^2;
f(38)=(x(1,14)-x(1,11))^2+(x(2,14)-x(2,11))^2-d(38)^2;
f(39)=(x(1,16)-x(1,11))^2+(x(2,16)-x(2,11))^2-d(39)^2;
f(40)=(x(1,14)-x(1,12))^2+(x(2,14)-x(2,12))^2-d(40)^2;
f(41)=(x(1,18)-x(1,12))^2+(x(2,18)-x(2,12))^2-d(41)^2;
f(42)=(x(1,14)-x(1,13))^2+(x(2,14)-x(2,13))^2-d(42)^2;
f(43)=(x(1,15)-x(1,13))^2+(x(2,15)-x(2,13))^2-d(43)^2;
f(44)=(x(1,19)-x(1,15))^2+(x(2,19)-x(2,15))^2-d(44)^2;
f(45)=(x(1,22)-x(1,15))^2+(x(2,22)-x(2,15))^2-d(45)^2;
f(46)=(x(1,17)-x(1,16))^2+(x(2,17)-x(2,16))