matlab出错 “Inner matrix dimensions must agree.”function result = XYZtoBL(X,Y,Z)format long ga=6378137.0000000000; %a为地球椭圆长半径e2=0.00669438002290; %e为地球第一偏心率 %进行迭代初值赋值if(X>0)L=atand(Y/X);elseL=atan
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 02:35:11
matlab出错 “Inner matrix dimensions must agree.”function result = XYZtoBL(X,Y,Z)format long ga=6378137.0000000000; %a为地球椭圆长半径e2=0.00669438002290; %e为地球第一偏心率 %进行迭代初值赋值if(X>0)L=atand(Y/X);elseL=atan
matlab出错 “Inner matrix dimensions must agree.”
function result = XYZtoBL(X,Y,Z)
format long g
a=6378137.0000000000; %a为地球椭圆长半径
e2=0.00669438002290; %e为地球第一偏心率
%进行迭代初值赋值
if(X>0)
L=atand(Y/X);
else
L=atand(Y/X)+180;
end
B=atand(Z/sqrt(X^2+Y^2));
W=sqrt(1-e2*sin(B*pi/180));
N=a/W;
H=sqrt(X^2+Y^2)/cos(B*pi/180)-N;
M=a*(1-e2)/W^3;
k1=sin(B*pi/180);
k11=cos(B*pi/180);
k2=sin(L*pi/180);
k22=cos(L*pi/180);
JI=[k2/(N+H)*k11 k22/(N+H)*k11 0;k1*k22/(M+H) k1*k2/(M+H) k11/(M+H);k1*k2 k2*k11 k1];
U=[(N+H)*k11*k22-X;(N+H)*k11*k2-Y;(N*(1-e2)+H)*k1-Z];
T=[L;B;H];
Q=T-JI.*U;
while norm(Y-T,inf)>=0.00001
T=0.5*Q;
JI=[k2/(N+H)*k11 k22/(N+H)*k11 0;k1*k22/(M+H) k1*k2/(M+H) k11/(M+H);k1*k2 k2*k11 k1];
U=[(N+H)*k11*k22-X (N+H)*k11*k2-Y (N*(1-e2)+H)*k1-Z];
Q=T-JI.*U;
end
result=T;
result
运行结果
Error using ==> mtimesInner matrix dimensions must agree.
Error in ==> XYZtoBL at 34 Q=T-JI*U;
求大侠指教啊.
matlab出错 “Inner matrix dimensions must agree.”function result = XYZtoBL(X,Y,Z)format long ga=6378137.0000000000; %a为地球椭圆长半径e2=0.00669438002290; %e为地球第一偏心率 %进行迭代初值赋值if(X>0)L=atand(Y/X);elseL=atan
1、应该把点乘(.*)改为矩阵乘(*).while语句的上面和循环体里面各有一处,都要改.不过,有点奇怪的是,你贴出来的代码里面是点乘,而下面的报错信息却是矩阵乘.
2、while循环体中的这一句
U=[(N+H)*k11*k22-X (N+H)*k11*k2-Y (N*(1-e2)+H)*k1-Z];
改成
U=[(N+H)*k11*k22-X; (N+H)*k11*k2-Y; (N*(1-e2)+H)*k1-Z];
这一点也有些奇怪:while的上面有一句是按照列向量写的,不知为什么到这里就成了行向量.
另外,JI和U在循环体内没有更新(虽然每步都计算,但值不变),是不是有问题?如果确信没问题,那么循环体里面的这两句完全可以删掉.
3、while循环的迭代本质就是
Q = 0.5*Q + e
其中e=JI*U,而结束条件是 Y-0.5*Q 的范数足够小.这样的迭代看上去有点莫名其妙,是不是迭代的结束条件搞错了?