wszc 发表于 2006-11-5 20:55

求助 关于循环求解

各位大哥大姐
    我设置了一个循环用于求解各种参数下方程的解
    程序如下:
    for b=3.9:0.005:4.9;
      for u=0:1:9
            .
            .
            .
   end
end

为什么总是解不出来
结果是            Index exceeds matrix dimensions.
可是把 b 设置为 b=3.9:0.01:4.9   就可以解出来
怪怪这是怎么回事啊


function =original2
%以向量形式表示各坐标及计算出来的时间t
syms x;
format long
i=1;
k=[];
R=;

for b=3.9:0.005:4.2
    for u=0:0.1:9

   nv1=5.793256899*cos(0.5329537403e-1*x)*sin(b)+11.68766331*cos(0.5329537403e-1*x)*cos(b)+11.68766331*sin(0.5329537403e-1*x)*sin(b)+.1674083755*sin(0.5329537403e-1*x)*sin(b)*u-6.814910728+.1674083755*cos(0.5329537403e-1*x)*cos(b)*u-.2837204276*cos(b)-.4858294314*sin(b)-5.793256899*sin(0.5329537403e-1*x)*cos(b)+4.183477253*sin(0.5329537403e-1*x)-7.163588457*cos(0.5329537403e-1*x);
a=subs(solve(nv1));
t=a(1);
if abs(5.793256899*cos(0.5329537403e-1*t)*sin(b)+11.68766331*cos(0.5329537403e-1*t)*cos(b)+11.68766331*sin(0.5329537403e-1*t)*sin(b)+.1674083755*sin(0.5329537403e-1*t)*sin(b)*u-6.814910728+.1674083755*cos(0.5329537403e-1*t)*cos(b)*u-.2837204276*cos(b)-.4858294314*sin(b)-5.793256899*sin(0.5329537403e-1*t)*cos(b)+4.183477253*sin(0.5329537403e-1*t)-7.163588457*cos(0.5329537403e-1*t))<0.00001
if a(1)>0
w1=41.42998229*cos(.1745329252*t)*cos(0.5329537403e-1*t)*sin(b)+0.9266731783e-1*cos(.1745329252*t)*cos(0.5329537403e-1*t)*sin(b)*u-41.42998229*cos(.1745329252*t)*sin(0.5329537403e-1*t)*cos(b)-0.9266731783e-1*cos(.1745329252*t)*sin(0.5329537403e-1*t)*cos(b)*u+21.56690785*cos(.1745329252*t)*cos(0.5329537403e-1*t)+36.93015231*cos(.1745329252*t)*sin(0.5329537403e-1*t)+146.5000000*sin(.1745329252*t)*sin(0.5329537403e-1*t)*sin(b)+.3276796492*sin(.1745329252*t)*sin(0.5329537403e-1*t)*sin(b)*u+146.5000000*sin(.1745329252*t)*cos(0.5329537403e-1*t)*cos(b)+.3276796492*sin(.1745329252*t)*cos(0.5329537403e-1*t)*cos(b)*u+76.26245115*sin(.1745329252*t)*sin(0.5329537403e-1*t)-130.5882121*sin(.1745329252*t)*cos(0.5329537403e-1*t)+.9062219815*cos(.1745329252*t)*u+.5755076022*cos(.1745329252*t)+6.356200000*sin(.1745329252*t);
w2=-41.42998229*sin(.1745329252*t)*cos(0.5329537403e-1*t)*sin(b)-0.9266731783e-1*sin(.1745329252*t)*cos(0.5329537403e-1*t)*sin(b)*u+41.42998229*sin(.1745329252*t)*sin(0.5329537403e-1*t)*cos(b)+0.9266731783e-1*sin(.1745329252*t)*sin(0.5329537403e-1*t)*cos(b)*u-21.56690785*sin(.1745329252*t)*cos(0.5329537403e-1*t)-36.93015231*sin(.1745329252*t)*sin(0.5329537403e-1*t)+146.5000000*cos(.1745329252*t)*sin(0.5329537403e-1*t)*sin(b)+.3276796492*cos(.1745329252*t)*sin(0.5329537403e-1*t)*sin(b)*u+146.5000000*cos(.1745329252*t)*cos(0.5329537403e-1*t)*cos(b)+.3276796492*cos(.1745329252*t)*cos(0.5329537403e-1*t)*cos(b)*u+76.26245115*cos(.1745329252*t)*sin(0.5329537403e-1*t)-130.5882121*cos(.1745329252*t)*cos(0.5329537403e-1*t)-.9062219815*sin(.1745329252*t)*u-.5755076022*sin(.1745329252*t)+6.356200000*cos(.1745329252*t);
w3=140.5197729*cos(0.5329537403e-1*t)*sin(b)+.3143035487*cos(0.5329537403e-1*t)*sin(b)*u-140.5197729*sin(0.5329537403e-1*t)*cos(b)-.3143035487*sin(0.5329537403e-1*t)*cos(b)*u+73.14936733*cos(0.5329537403e-1*t)+125.2575147*sin(0.5329537403e-1*t)-.2671848942*u-2.291379108;
A00=w1;
B00=atan(sqrt(w2^2+w3^2)/w1)*180/pi;
R=;
k(i,:)=R;
i=i+1;
end
end

t=a(2);
if abs(5.793256899*cos(0.5329537403e-1*t)*sin(b)+11.68766331*cos(0.5329537403e-1*t)*cos(b)+11.68766331*sin(0.5329537403e-1*t)*sin(b)+.1674083755*sin(0.5329537403e-1*t)*sin(b)*u-6.814910728+.1674083755*cos(0.5329537403e-1*t)*cos(b)*u-.2837204276*cos(b)-.4858294314*sin(b)-5.793256899*sin(0.5329537403e-1*t)*cos(b)+4.183477253*sin(0.5329537403e-1*t)-7.163588457*cos(0.5329537403e-1*t))<0.00001
if a(2)>0
w1=41.42998229*cos(.1745329252*t)*cos(0.5329537403e-1*t)*sin(b)+0.9266731783e-1*cos(.1745329252*t)*cos(0.5329537403e-1*t)*sin(b)*u-41.42998229*cos(.1745329252*t)*sin(0.5329537403e-1*t)*cos(b)-0.9266731783e-1*cos(.1745329252*t)*sin(0.5329537403e-1*t)*cos(b)*u+21.56690785*cos(.1745329252*t)*cos(0.5329537403e-1*t)+36.93015231*cos(.1745329252*t)*sin(0.5329537403e-1*t)+146.5000000*sin(.1745329252*t)*sin(0.5329537403e-1*t)*sin(b)+.3276796492*sin(.1745329252*t)*sin(0.5329537403e-1*t)*sin(b)*u+146.5000000*sin(.1745329252*t)*cos(0.5329537403e-1*t)*cos(b)+.3276796492*sin(.1745329252*t)*cos(0.5329537403e-1*t)*cos(b)*u+76.26245115*sin(.1745329252*t)*sin(0.5329537403e-1*t)-130.5882121*sin(.1745329252*t)*cos(0.5329537403e-1*t)+.9062219815*cos(.1745329252*t)*u+.5755076022*cos(.1745329252*t)+6.356200000*sin(.1745329252*t);
w2=-41.42998229*sin(.1745329252*t)*cos(0.5329537403e-1*t)*sin(b)-0.9266731783e-1*sin(.1745329252*t)*cos(0.5329537403e-1*t)*sin(b)*u+41.42998229*sin(.1745329252*t)*sin(0.5329537403e-1*t)*cos(b)+0.9266731783e-1*sin(.1745329252*t)*sin(0.5329537403e-1*t)*cos(b)*u-21.56690785*sin(.1745329252*t)*cos(0.5329537403e-1*t)-36.93015231*sin(.1745329252*t)*sin(0.5329537403e-1*t)+146.5000000*cos(.1745329252*t)*sin(0.5329537403e-1*t)*sin(b)+.3276796492*cos(.1745329252*t)*sin(0.5329537403e-1*t)*sin(b)*u+146.5000000*cos(.1745329252*t)*cos(0.5329537403e-1*t)*cos(b)+.3276796492*cos(.1745329252*t)*cos(0.5329537403e-1*t)*cos(b)*u+76.26245115*cos(.1745329252*t)*sin(0.5329537403e-1*t)-130.5882121*cos(.1745329252*t)*cos(0.5329537403e-1*t)-.9062219815*sin(.1745329252*t)*u-.5755076022*sin(.1745329252*t)+6.356200000*cos(.1745329252*t);
w3=140.5197729*cos(0.5329537403e-1*t)*sin(b)+.3143035487*cos(0.5329537403e-1*t)*sin(b)*u-140.5197729*sin(0.5329537403e-1*t)*cos(b)-.3143035487*sin(0.5329537403e-1*t)*cos(b)*u+73.14936733*cos(0.5329537403e-1*t)+125.2575147*sin(0.5329537403e-1*t)-.2671848942*u-2.291379108;
A00=w1;
B00=atan(sqrt(w2^2+w3^2)/w1)*180/pi;
R=;
k(i,:)=R;
i=i+1;
end
end
    end
end
k;

jimin 发表于 2006-11-5 22:54

给完整的程序,否则别人看不懂的

athlon2004 发表于 2006-11-5 23:06

我认为是两者的数据形成不了方阵
在步长是0.01的是9个数据 而下一个循环也是9个数据 程序成功
如果步长变成0.005的话 那么就要变成20个数据 形成不了一一对应的关系
至少对你的目前的程序来说是这样的

wszc 发表于 2006-11-6 09:13

不对啊
不应该要成为方阵啊    我试过了
设为
for b=3.9:0.005:4.2;
      for u=0:1:9
结果就可以计算出来   感觉挺奇怪的
好像是计算的次数太多了就出错
页: [1]
查看完整版本: 求助 关于循环求解