matlab-常见经典平差-程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

希望本人编写的经典平差可以对matlab初学者以及测绘专业的学生有用Bycowboyfunctionvoid()sprintf('请选择平差类型')sprintf('1:参数平差\n2:条件平差\n3:具有条件的参数平差\n4:具有参数的条件平差\n')a=input('请输入对应号码\n');switch(a)case1%参数平差V=AX-Lsprintf('1:参数平差V=AX-L')n=input('请输入n=');t=input('请输入t=');A=input('请输入系数矩阵A=');L=input('请输入常数项矩阵L=');P=diag(input('请输入权阵P='))%P=input('请输入权阵P=');N=A'*P*A;U=A'*P*L;sprintf('开始计算')X=inv(N)*(U);V=A*X-L;Qx=inv(N);u=sqrt((V'*P*V)/(n-t));fid=fopen('data.txt','wt');%写入文件路径,文件输出fprintf(fid,'=====================参数平差:V=AX-L=====================\n');fprintf(fid,'输出n,t\n');fprintf(fid,'%12.5f%12.5f\n',n,t);%n,tfprintf(fid,'输出矩阵A\n')[m,n]=size(A);%Afori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',A(i,j));elsefprintf(fid,'%12.5f\t',A(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵L\n');[m,n]=size(L);%Lfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',L(i,j));elsefprintf(fid,'%12.5f\t',L(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵P\n');[m,n]=size(P);%Pfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',P(i,j));elsefprintf(fid,'%12.5f\t',P(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵X\n');[m,n]=size(X);%Xfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',X(i,j));elsefprintf(fid,'%12.5f\t',X(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵V\n');[m,n]=size(V);%Vfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',V(i,j));elsefprintf(fid,'%12.5f\t',V(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵Qx\n');[m,n]=size(Qx);%Qxfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',Qx(i,j));elsefprintf(fid,'%12.5f\t',Qx(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出单位权中误差u\n');[m,n]=size(u);%ufori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',u(i,j));elsefprintf(fid,'%12.5f\t',u(i,j));endendendfprintf(fid,'\n');fclose(fid);case2%条件平差BV+W=0sprintf('2:条件平差BV+W=0')n=input('请输入n=');t=input('请输入t=');B=input('请输入系数矩阵B=');W=input('请输入自由项向量W=');P=input('请输入权阵P=');sprintf('开始计算')K=-inv((B*inv(P)*B'))*W;V=inv(P)*B'*K;u=sqrt((V'*P*V)/(n-t));Ql=inv(P)-inv(P)*B'*inv(B*inv(P)*B')*B*inv(P);fid=fopen('data.txt','wt');%写入文件路径,文件输出fprintf(fid,'=====================条件平差:BV+W=0=====================\n');fprintf(fid,'输出n,t\n');fprintf(fid,'%12.5f%12.5f\n',n,t);%n,tfprintf(fid,'输出矩阵B\n');[m,n]=size(B);%Bfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',B(i,j));elsefprintf(fid,'%12.5f\t',B(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵W\n');[m,n]=size(W);%Wfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',W(i,j));elsefprintf(fid,'%12.5f\t',W(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵P\n');[m,n]=size(P);%Pfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',P(i,j));elsefprintf(fid,'%12.5f\t',P(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵V\n');[m,n]=size(V);%Vfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',V(i,j));elsefprintf(fid,'%12.5f\t',V(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵Qx\n');[m,n]=size(Ql);%Qlfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',Ql(i,j));elsefprintf(fid,'%12.5f\t',Ql(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出单位权中误差u\n');[m,n]=size(u);%ufori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',u(i,j));elsefprintf(fid,'%12.5f\t',u(i,j));endendendfprintf(fid,'\n');fclose(fid);case3%具有条件的参数平差%参数平差V=AX-L%条件平差BX+W=0sprintf('3:具有条件的参数平差V=AX-L;BX+W=0')n=input('请输入n=');t=input('请输入t=');r=input('请输入r=');A=input('请输入误差方程系数矩阵A=');L=input('请输入常数项矩阵L=');B=input('请输入条件方程系数矩阵B=');W=input('请输入自由项向量W=');P=input('请输入权阵P=');sprintf('开始计算')K=-(inv(B*inv(A'*P*A)*B'))*(W+B*inv(A'*P*A)*A'*P*L)X=(inv(A'*P*A))*(B'*K+A'*P*L)N=(A'*P*A)M=B*inv(N)*B'Qx=inv(N)-inv(N)*B'*inv(M)*B*inv(N)u=sqrt((V'*P*V)/(n-t+r))fid=fopen('data.txt','wt');%写入文件路径,文件输出fprintf(fid,'=====================具有条件的参数平差:V=AX-L;BX+W=0===========================\n');fprintf(fid,'输出n,t,r\n');fprintf(fid,'%12.5f%12.5f%12.5f\n',n,t,r);%n,t,rfprintf(fid,'输出矩阵A\n');[m,n]=size(A);%Afori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',A(i,j));elsefprintf(fid,'%12.5f\t',A(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵L\n');[m,n]=size(L);%Lfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',L(i,j));elsefprintf(fid,'%12.5f\t',L(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵B\n');[m,n]=size(B);%Bfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',B(i,j));elsefprintf(fid,'%12.5f\t',B(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵W\n');[m,n]=size(W);%Wfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',W(i,j));elsefprintf(fid,'%12.5f\t',W(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵P\n');[m,n]=size(P);%Pfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',P(i,j));elsefprintf(fid,'%12.5f\t',P(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵X\n');[m,n]=size(X);%Xfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',X(i,j));elsefprintf(fid,'%12.5f\t',X(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵V\n');[m,n]=size(V);%Vfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',V(i,j));elsefprintf(fid,'%12.5f\t',V(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出矩阵Qx\n');[m,n]=size(Qx);%Qxfori=1:1:mforj=1:1:nifj==nfprintf(fid,'%12.5f\n',Qx(i,j));elsefprintf(fid,'%12.5f\t',Qx(i,j));endendendfprintf(fid,'\n');fprintf(fid,'输出单位权中

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功