声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4483|回复: 10

[编程技巧] 关于非线性超定方程组的求解

[复制链接]
发表于 2007-5-28 12:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
本人的毕业设计是做摄像机标定,求出了一系列点在世界坐标系和图象坐标系的坐标,并且也知道了是用哪个方程求解,只是不知道怎么用MATLAB编程(要用最小二乘法).希望哪位前辈帮下忙(可提出适当的报酬)
qq:79514936
email:oldlarge@eyou.com

[ 本帖最后由 eight 于 2007-5-28 15:29 编辑 ]
回复
分享到:

使用道具 举报

 楼主| 发表于 2007-5-28 13:16 | 显示全部楼层
方程:Z*[u v 1]'=[x 0 u1 0;0 y v1 0;0 1 1 0]*[R t;0' 1][Xw Yw Zw 1]
其中Z,u,v,Xw,Yw,Zw已知,x,u1,y,v1,R,t等求,R为3*3的正交锯阵,t为3维向量
并且已知8组数据,哪位前辈帮下啊(毕业设计快结束了)
发表于 2007-5-28 14:27 | 显示全部楼层
请将参数值给出,文件最好也能用word上传一下.
 楼主| 发表于 2007-6-4 11:21 | 显示全部楼层
f(1)=ax*R1*XW+U0*R7*XW+ax*R2*YW+U0*R8*YW+ax*R3*ZW+U0*R9*ZW+ax*T1+U0*R7-R7*XW*U-R8*YW*U-R9*ZW*U-T3*U;

f(2)=ay*R4*XW+V0*R7*XW+ay*R5*YW+V0*R8*YW+ay*R6*ZW+V0*R9*ZW+ay*T2+V0*T3-R7*XW*V-R8*YW*V-R9*ZW*V-T3*V;

f(11)=R1^2+R4^2+R7^2-1;

f(12)=R2^2+R5^2+R8^2-1;

f(13)=R3^2+R6^2+R9^2-1;

f(14)=R1*R2+R4*R5+R7*R8;

f(15)=R1*R3+R4*R6+R7*R9;

f(16)=R2*R3+R5*R6+R8*R9;
在方程f(1)和f(2)中,U,V,XW,YW,ZW已知,并有8组数据,给出如下:

>>U1=39.6371;
>> V1=125.282;
>> XW1=286.6371;
>> YW1=780.2820;
>> ZW1=477;

>>U2=109.136;
>> V2=124.229;
>> XW2=356.1360;
>> YW2=779.229;
>>ZW2=477;

>>U3=220.756;
>> V3=123.176;
>> XW3=467.7560;
>> YW3=778.176;
>>
ZW3=477;

>>U4=310.262;
>> V4=121.07;
>> XW4=557.2620;
>> YW4=776.0700;
>>ZW4=477;

>>U5=426.094;
>> V5=121.07;
>> XW5=673.094;
>> YW5=776.07;
>>ZW5=477;

>>U6=501.911;
>>V6=120.017;
>>XW6=748.911;
>>YW6=775.017;
>>ZW6=477;

>>U7=624.061;
>>V7=120.017;
>>XW7=871.061;
>>YW7=775.017;
>>ZW7=477;

>>U8=699.878;
>>V8=120.017;
>>XW8=946.878,
>>YW8=775.017;
>>ZW8=477;
分别代入f(1)和f(2)得到16个方程,再与f(11)~f(16)联成含有24个方程的方程组,解出ax,ay,U0,VO,T1,T2,T3,R1,R2,R3,R4,R5,R6,R7,R8,R9共16个未知数,由于是超定方程组,所以要用到最小二乘法。
发表于 2007-6-5 09:32 | 显示全部楼层
正确写出方程组,用fsolve可求解之;
或者用1stOpt也可以求解.
注意:结果有好几个参数为零.
 楼主| 发表于 2007-6-5 12:48 | 显示全部楼层
可是我这个是超定方程组,要用到最小二乘法.
麻烦你看下我的程序(这个程序只用到5组数据,也就是只建立 含有16个方程的方程组):
  
function y=fei2(x)
ax=x(1);
ay=x(2);
U0=x(3);
V0=x(4);
T1=x(5);
T2=x(6);
T3=x(7);
R1=x(8);
R2=x(9);
R3=x(10);
R4=x(11);
R5=x(12);
R6=x(13);
R7=x(14);
R8=x(15);
R9=x(16);
y=[ax*R1*286.6371+U0*R7*286.6371+ax*R2*780.2820+U0*R8*780.2820+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*286.6371*39.6371-R8*780.2820*39.6371-R9*477*39.6371-T3*39.6371;ax*R1*356.1360+U0*R7*356.1360+ax*R2*779.229+U0*R8*779.229+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*356.1360*109.136-R8*779.229*109.136-R9*477*109.136-T3*109.136;ax*R1*467.7560+U0*R7*467.7560+ax*R2*778.176+U0*R8*778.176+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*467.7560*220.756-R8*778.176*220.756-R9*477*220.756-T3*220.756;ax*R1*557.2620+U0*R7*557.2620+ax*R2*776.0700+U0*R8*776.0700+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*557.2620*310.262-R8*776.0700*310.262-R9*477*310.262-T3*310.262;ax*R1*673.094+U0*R7*673.094+ax*R2*776.07+U0*R8*776.07+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*673.094*426.094-R8*776.07*426.094-R9*477*426.094-T3*426.094;ay*R4*286.6371+V0*R7*286.6371+ay*R5*780.2820+V0*R8*780.2820+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*286.6371*125.282-R8*780.2820*125.282-R9*477*125.282-T3*125.282;ay*R4*356.1360+V0*R7*356.1360+ay*R5*779.229+V0*R8*779.229+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*356.1360*124.229-R8*779.229*124.229-R9*477*124.229-T3*124.229;ay*R4*467.7560+V0*R7*467.7560+ay*R5*778.176+V0*R8*778.176+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*467.7560*123.176-R8*778.176*123.176-R9*477*123.176-T3*123.176;ay*R4*557.2620+V0*R7*557.2620+ay*R5*776.0700+V0*R8*776.0700+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*557.2620*121.07-R8*776.0700*121.07-R9*477*121.07-T3*121.07;ay*R4*673.094+V0*R7*673.094+ay*R5*776.07+V0*R8*776.07+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*673.094*121.07-R8*776.07*121.07-R9*477*121.07-T3*121.07;R1^2+R4^2+R7^2-1;R2^2+R5^2+R8^2-1;R3^2+R6^2+R9^2-1;R1*R2+R4*R5+R7*R8;R1*R3+R4*R6+R7*R9;R2*R3+R5*R6+R8*R9];
阿肥 12:44:16
function f=fei(x)
ax=x(1);
ay=x(2);
U0=x(3);
V0=x(4);
T1=x(5);
T2=x(6);
T3=x(7);
R1=x(8);
R2=x(9);
R3=x(10);
R4=x(11);
R5=x(12);
R6=x(13);
R7=x(14);
R8=x(15);
R9=x(16);
f(1)=ax*R1*286.6371+U0*R7*286.6371+ax*R2*780.2820+U0*R8*780.2820+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*286.6371*39.6371-R8*780.2820*39.6371-R9*477*39.6371-T3*39.6371;
f(2)=ax*R1*356.1360+U0*R7*356.1360+ax*R2*779.229+U0*R8*779.229+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*356.1360*109.136-R8*779.229*109.136-R9*477*109.136-T3*109.136;
f(3)=ax*R1*467.7560+U0*R7*467.7560+ax*R2*778.176+U0*R8*778.176+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*467.7560*220.756-R8*778.176*220.756-R9*477*220.756-T3*220.756;
f(4)=ax*R1*557.2620+U0*R7*557.2620+ax*R2*776.0700+U0*R8*776.0700+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*557.2620*310.262-R8*776.0700*310.262-R9*477*310.262-T3*310.262;
f(5)=ax*R1*673.094+U0*R7*673.094+ax*R2*776.07+U0*R8*776.07+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*673.094*426.094-R8*776.07*426.094-R9*477*426.094-T3*426.094;

f(6)=ay*R4*286.6371+V0*R7*286.6371+ay*R5*780.2820+V0*R8*780.2820+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*286.6371*125.282-R8*780.2820*125.282-R9*477*125.282-T3*125.282;
f(7)=ay*R4*356.1360+V0*R7*356.1360+ay*R5*779.229+V0*R8*779.229+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*356.1360*124.229-R8*779.229*124.229-R9*477*124.229-T3*124.229;
f(8)=ay*R4*467.7560+V0*R7*467.7560+ay*R5*778.176+V0*R8*778.176+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*467.7560*123.176-R8*778.176*123.176-R9*477*123.176-T3*123.176;
f(9)=ay*R4*557.2620+V0*R7*557.2620+ay*R5*776.0700+V0*R8*776.0700+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*557.2620*121.07-R8*776.0700*121.07-R9*477*121.07-T3*121.07;
f(10)=ay*R4*673.094+V0*R7*673.094+ay*R5*776.07+V0*R8*776.07+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*673.094*121.07-R8*776.07*121.07-R9*477*121.07-T3*121.07;
f(11)=R1^2+R4^2+R7^2-1;
f(12)=R2^2+R5^2+R8^2-1;
f(13)=R3^2+R6^2+R9^2-1;
f(14)=R1*R2+R4*R5+R7*R8;
f(15)=R1*R3+R4*R6+R7*R9;
f(16)=R2*R3+R5*R6+R8*R9;
end

用fsolve求解,但是取了好多初值都无法收敛.
超定的就更不会了.
 楼主| 发表于 2007-6-5 12:50 | 显示全部楼层
上面的弄错了.下面是我要说的话
可是我这个是超定方程组,要用到最小二乘法.
下面是我的程序,这个程序只用到5组数据,也就是只建立含有16个方程的方程组:
function f=fei(x)
ax=x(1);
ay=x(2);
U0=x(3);
V0=x(4);
T1=x(5);
T2=x(6);
T3=x(7);
R1=x(8);
R2=x(9);
R3=x(10);
R4=x(11);
R5=x(12);
R6=x(13);
R7=x(14);
R8=x(15);
R9=x(16);
f(1)=ax*R1*286.6371+U0*R7*286.6371+ax*R2*780.2820+U0*R8*780.2820+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*286.6371*39.6371-R8*780.2820*39.6371-R9*477*39.6371-T3*39.6371;
f(2)=ax*R1*356.1360+U0*R7*356.1360+ax*R2*779.229+U0*R8*779.229+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*356.1360*109.136-R8*779.229*109.136-R9*477*109.136-T3*109.136;
f(3)=ax*R1*467.7560+U0*R7*467.7560+ax*R2*778.176+U0*R8*778.176+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*467.7560*220.756-R8*778.176*220.756-R9*477*220.756-T3*220.756;
f(4)=ax*R1*557.2620+U0*R7*557.2620+ax*R2*776.0700+U0*R8*776.0700+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*557.2620*310.262-R8*776.0700*310.262-R9*477*310.262-T3*310.262;
f(5)=ax*R1*673.094+U0*R7*673.094+ax*R2*776.07+U0*R8*776.07+ax*R3*477+U0*R9*477+ax*T1+U0*R7-R7*673.094*426.094-R8*776.07*426.094-R9*477*426.094-T3*426.094;

f(6)=ay*R4*286.6371+V0*R7*286.6371+ay*R5*780.2820+V0*R8*780.2820+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*286.6371*125.282-R8*780.2820*125.282-R9*477*125.282-T3*125.282;
f(7)=ay*R4*356.1360+V0*R7*356.1360+ay*R5*779.229+V0*R8*779.229+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*356.1360*124.229-R8*779.229*124.229-R9*477*124.229-T3*124.229;
f(8)=ay*R4*467.7560+V0*R7*467.7560+ay*R5*778.176+V0*R8*778.176+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*467.7560*123.176-R8*778.176*123.176-R9*477*123.176-T3*123.176;
f(9)=ay*R4*557.2620+V0*R7*557.2620+ay*R5*776.0700+V0*R8*776.0700+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*557.2620*121.07-R8*776.0700*121.07-R9*477*121.07-T3*121.07;
f(10)=ay*R4*673.094+V0*R7*673.094+ay*R5*776.07+V0*R8*776.07+ay*R6*477+V0*R9*477+ay*T2+V0*T3-R7*673.094*121.07-R8*776.07*121.07-R9*477*121.07-T3*121.07;
f(11)=R1^2+R4^2+R7^2-1;
f(12)=R2^2+R5^2+R8^2-1;
f(13)=R3^2+R6^2+R9^2-1;
f(14)=R1*R2+R4*R5+R7*R8;
f(15)=R1*R3+R4*R6+R7*R9;
f(16)=R2*R3+R5*R6+R8*R9;
end

用fsolve求解,但是取了好多初值都无法收敛.
超定的就更不会了.
发表于 2007-6-5 14:51 | 显示全部楼层
将22个方程全部写入,fsolve求解没有问题,只是矩阵有奇异性,结果可能不太可靠.
所以我前面的回帖加了一句: 或用1stOpt求解(也正好发挥后者的强项).
------------善于针对问题, 运用各种软件的优点就行了.

评分

1

查看全部评分

 楼主| 发表于 2007-6-7 15:48 | 显示全部楼层
你取了什么样的初值啊,我试过用fslove求解但是无法收敛.
我的课题就是用MATLAB,istOpt不会啊
发表于 2007-6-7 16:20 | 显示全部楼层
初值全部取为1-----不过结果可能不可靠, 建议根据计算的结果,多取几次初值试试.
最好是学习用1stOpt求解之.
发表于 2007-6-7 16:24 | 显示全部楼层
如果不限范围,有很多组解:
ax: 4.86041176354153E-10
r1: 0.997220723507545
u0: 8.54525338455659E-10
r7: 1.75949638541796E-12
r2: 0.0745039256211607
r8: 6.55963112157226E-11
r3: -1.93008266366276E-11
r9: -1.00000094033949
t1: 370.497203628225
t3: 477.000448490133
ay: -1.10323647781956E-11
r4: -0.0745039343427432
v0: 272.244673133603
r5: 0.997220723423885
r6: 1.22061269890438E-8
t2: -1107.88130871536
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-24 19:45 , Processed in 0.069481 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表