声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1411|回复: 2

[混合编程] 新手有问,运行出错,求高手指点!

[复制链接]
发表于 2012-5-6 22:22 | 显示全部楼层 |阅读模式

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

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

x
程序代码完整为:
function y=ill(t,x)
a=1;b=0.3;
y=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';

ts=0;50;
x0=[0.02,0.98];
[t,x]=ode45('ill',ts,x0);[t,x]
plot(t,x(:,1),t,x(:,2)),grid,pause
plot(x(:,2),x(:,1)),grid,
我的做法一:

function y=ill(t,x)
a=1;b=0.3;
y=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';

保存为m文件,关闭然后回到command window

ts=0;50;
x0=[0.02,0.98];
[t,x]=ode45('ill',ts,x0);[t,x]
plot(t,x(:,1),t,x(:,2)),grid,pause
plot(x(:,2),x(:,1)),grid,
copy进去回车出现
??? Error using ==> odearguments at 101
The last entry in tspan must be different from the first
entry.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...


我的做法二:

function y=ill(t,x)
a=1;b=0.3;
y=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';

保存为m文件,然后回到command window
输入 ill ,回车却出现
??? Input argument "x" is undefined.

Error in ==> ill at 3
y=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';


希望能得到高人指点,谢谢了!
回复
分享到:

使用道具 举报

 楼主| 发表于 2012-5-6 22:26 | 显示全部楼层
急待高人出现!
发表于 2012-5-7 08:28 | 显示全部楼层
一、你的程序里有明显的错误,ts=0;50;应该改为ts=0:50;这是导致你程序出错的原因。
二、你做法二出现错误是正常的,ill函数的调用需要定义x,直接调用ill显然会出现这样的错误
ps:写代码是个细活,一个符号的错误很可能将导致整个程序的运行失败

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-5-20 21:57 , Processed in 0.058778 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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