24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1200  |  回复: 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的回帖

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的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

忘了x是10个,用x=ones(1,10);
这个x是输入值,得你知道数值是多少输入。
showmethemoney
5楼2012-08-23 10:23:37
已阅   回复此楼   关注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的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖

★ ★ ★ ★
wzycrfpxz: 金币+4, ★★★很有帮助 2012-08-23 14:33:06
引用回帖:
6楼: Originally posted by wzycrfpxz at 2012-08-23 10:24:03
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=;

end



命令窗口:x0=;
tic ...

if少了一个end,在dx=....那之前加个end。
你原来的如果if满足了就不计算dx了,所以出错。
showmethemoney
7楼2012-08-23 11:51:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

wzycrfpxz

新虫 (初入文坛)

引用回帖:
7楼: Originally posted by csgt0 at 2012-08-23 11:51:47
if少了一个end,在dx=....那之前加个end。
你原来的如果if满足了就不计算dx了,所以出错。...

谢谢
8楼2012-08-23 14:32:59
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 wzycrfpxz 的主题更新
信息提示
请填处理意见