24小时热门版块排行榜    

查看: 1417  |  回复: 7
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

wzycrfpxz

新虫 (初入文坛)

[求助] matlab 问题求助,一段程序出错,求纠错

function dx=lunar(t,x,u)
syms t x u;
u0=45760.00;
if ((x(6)/x(5))*cos(atan(x(7)/x(6)))+(x(7)/x(5))*sin(atan(x(7)/x(6)))-(3.283e-4)*x(10))+1>0
    u=u0;

else   u=0.00;
dx=[(u/x(5))*cos(atan(x(7)/x(6)));
    (u/x(5))*sin(atan(x(7)/x(6)));
    x(1);
    x(2);
    (-3.281e-4)*u;
    0;
    -x(9);
    0;
    0;
    (u/x(5)^2)*cos(atan(x(7)/x(6)))*x(6)+(u/x(5)^2)*sin(atan(x(7)/x(6)))*x(7)];

end

??? Error using ==> mupadmex
Error in MuPAD command: Index exceeds matrix dimensions.

Error in ==> sym.sym>sym.subsref at 1366
            B = mupadmex('mllib::subsref',A.s,inds{:});

Error in ==> lunar at 4
if ((x(6)/x(5))*cos(atan(x(7)/x(6)))+(x(7)/x(5))*sin(atan(x(7)/x(6)))-(3.283e-4)*x(10))+1>0
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wzycrfpxz

新虫 (初入文坛)

引用回帖:
4楼: Originally posted by csgt0 at 2012-08-23 10:22:14
你怎么调用函数的?你这是一个函数,得用别的数据调用,比如你在命令窗口输入以下试试:
x=ones(1,7);
t=1;
u=2;
dx=lunar(t,x,u);
这样就可以运行了。但是你的t和u好像根本与外面没有关系,因为再里面计算了
...

function dx=lunar(t,x)

if ((x(6)/x(5))*cos(atan(x(7)/x(6)))+(x(7)/x(5))*sin(atan(x(7)/x(6)))-(3.283e-4)*x(10))+1>0
    u=45760.00;

else   u=0.00

dx=[(u/x(5))*cos(atan(x(7)/x(6)));
    (u/x(5))*sin(atan(x(7)/x(6)));
    x(1);
    x(2);
    (-3.281e-4)*u;
    0;
    -x(9);
    0;
    0;
    (u/x(5)^2)*cos(atan(x(7)/x(6)))*x(6)+(u/x(5)^2)*sin(atan(x(7)/x(6)))*x(7)];

end



命令窗口:x0=[150;-44;0;2300;9472.06;0.005;-0.003501;0;5.415e-4;1];
tic,[t,y]=ode45(@lunar,[0,100],x0);toc


Error in ==> lunar at 3
if ((x(6)/x(5))*cos(atan(x(7)/x(6)))+(x(7)/x(5))*sin(atan(x(7)/x(6)))-(3.283e-4)*x(10))+1>0

??? Error using ==> feval
Output argument "dx" (and maybe others) not assigned during call to "C:\Users\Administrator\Documents\MATLAB\lunar.m>lunar".

Error in ==> odearguments at 110
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ..
6楼2012-08-23 10:24:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 8 个回答

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖


感谢参与,应助指数 +1
wzycrfpxz: 金币+1, 有帮助 2012-08-23 11:23:26
把syms t x u;这句删掉
showmethemoney
2楼2012-08-23 10:02:49
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wzycrfpxz

新虫 (初入文坛)

引用回帖:
2楼: Originally posted by csgt0 at 2012-08-23 10:02:49
把syms t x u;这句删掉

??? Input argument "x" is undefined.

Error in ==> lunar at 4
if ((x(6)/x(5))*cos(atan(x(7)/x(6)))+(x(7)/x(5))*sin(atan(x(7)/x(6)))-(3.283e-4)*x(10))+1>0
删掉以后出现这个问题
3楼2012-08-23 10:06:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖

你怎么调用函数的?你这是一个函数,得用别的数据调用,比如你在命令窗口输入以下试试:
x=ones(1,7);
t=1;
u=2;
dx=lunar(t,x,u);
这样就可以运行了。但是你的t和u好像根本与外面没有关系,因为再里面计算了
所以你可以改成
dx=lunar(x)
showmethemoney
4楼2012-08-23 10:22:14
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 286分人工智能专业请求调剂愿意跨考! +3 lemonzzn 2026-03-17 5/250 2026-03-21 11:28 by lemonzzn
[考研] 336求调剂 +3 rmc8866 2026-03-21 3/150 2026-03-21 11:16 by 求调剂zz
[考研] 302求调剂 +11 呼呼呼。。。。 2026-03-17 11/550 2026-03-21 08:29 by JourneyLucky
[考研] 机械专硕299求调剂至材料 +3 kkcoco25 2026-03-16 4/200 2026-03-21 03:52 by JourneyLucky
[考研] 初始318分求调剂(有工作经验) +3 1911236844 2026-03-17 3/150 2026-03-21 02:33 by JourneyLucky
[考研] 南京大学化学376求调剂 +3 hisfailed 2026-03-19 6/300 2026-03-20 23:43 by hisfailed
[考研] 330求调剂 +4 小材化本科 2026-03-18 4/200 2026-03-20 23:13 by JourneyLucky
[考研] 323求调剂 +3 洼小桶 2026-03-18 3/150 2026-03-20 22:54 by JourneyLucky
[考研] 材料与化工 322求调剂 +4 然11 2026-03-19 4/200 2026-03-20 22:12 by luoyongfeng
[考研] 一志愿苏州大学材料求调剂,总分315(英一) +5 sbdksD 2026-03-19 5/250 2026-03-20 22:10 by luoyongfeng
[考研] 290求调剂 +7 ^O^乜 2026-03-19 7/350 2026-03-20 21:43 by JourneyLucky
[考研] 求调剂一志愿南京航空航天大学289分 +3 @taotao 2026-03-19 3/150 2026-03-20 21:34 by JourneyLucky
[考研] 0817 化学工程 299分求调剂 有科研经历 有二区文章 +22 rare12345 2026-03-18 22/1100 2026-03-20 20:39 by zhukairuo
[考研] 一志愿中国海洋大学,生物学,301分,求调剂 +5 1孙悟空 2026-03-17 6/300 2026-03-19 23:46 by zcl123
[考研] 材料考研调剂 +3 xwt。 2026-03-19 3/150 2026-03-19 11:22 by w沐阳w
[考研] 一志愿985,本科211,0817化学工程与技术319求调剂 +10 Liwangman 2026-03-15 10/500 2026-03-19 10:25 by 无际的草原
[考研] 085601专硕,总分342求调剂,地区不限 +5 share_joy 2026-03-16 5/250 2026-03-18 14:48 by haxia
[考研] 0854,计算机类招收调剂 +3 胡辣汤放糖 2026-03-15 6/300 2026-03-18 12:09 by 上岸上岸……..
[考研] 材料专硕326求调剂 +6 墨煜姒莘 2026-03-15 7/350 2026-03-17 17:10 by ruiyingmiao
[考研] 070300化学学硕求调剂 +6 太想进步了0608 2026-03-16 6/300 2026-03-16 16:13 by kykm678
信息提示
请填处理意见