声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1038|回复: 3

[编程技巧] 求助 关于循环求解

[复制链接]
发表于 2006-11-5 20:55 | 显示全部楼层 |阅读模式

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

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

x
各位大哥大姐  
    我设置了一个循环用于求解各种参数下方程的解
    程序如下:
    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   就可以解出来
怪怪  这是怎么回事啊


  1. function [b0,u0,t0]=original2
  2. %以向量形式表示各坐标  及计算出来的时间t
  3. syms x;
  4. format long
  5. i=1;
  6. k=[];
  7. R=[0 0 0 0 0 0 0 0];

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

  10.    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);
  11. a=subs(solve(nv1));
  12. t=a(1);
  13. 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
  14. if a(1)>0
  15. 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);
  16. 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);
  17. 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;
  18. A00=w1;
  19. B00=atan(sqrt(w2^2+w3^2)/w1)*180/pi;
  20. R=[b u t A00 B00 w1 w2 w3];
  21. k(i,:)=R;
  22. i=i+1;
  23. end
  24. end

  25. t=a(2);
  26. 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
  27. if a(2)>0
  28. 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);
  29. 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);
  30. 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;
  31. A00=w1;
  32. B00=atan(sqrt(w2^2+w3^2)/w1)*180/pi;
  33. R=[b u t A00 B00 w1 w2 w3];
  34. k(i,:)=R;
  35. i=i+1;
  36. end
  37. end
  38.     end
  39. end
  40. k;
复制代码
回复
分享到:

使用道具 举报

发表于 2006-11-5 22:54 | 显示全部楼层
给完整的程序,否则别人看不懂的
发表于 2006-11-5 23:06 | 显示全部楼层
我认为是两者的数据形成不了方阵
在步长是0.01的是9个数据 而下一个循环也是9个数据 程序成功
如果步长变成0.005的话 那么就要变成20个数据 形成不了一一对应的关系
至少对你的目前的程序来说是这样的

评分

1

查看全部评分

 楼主| 发表于 2006-11-6 09:13 | 显示全部楼层
不对啊
不应该要成为方阵啊    我试过了
设为
for b=3.9:0.005:4.2;
      for u=0:1:9
结果就可以计算出来   感觉挺奇怪的
好像是计算的次数太多了就出错
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-11-19 20:26 , Processed in 0.060245 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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