你要把内容
function y=ill(t,x)
a=1;b=0.3;
y=[a*x(1)*x(2)-b*x(1);-a*x(1)*x(2)];
保存为ill.m的文件,保存在当前工作的目录下
注意y要是列向量,中间用;不是,
然后运行后面的代码
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
或者用匿名函数的办法会简单点,不用保存m文件
a=1;b=0.3;
ill=@(t,x) [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);
subplot(211),
plot(t,x(:,1),t,x(:,2)),grid on
subplot(212),
plot(x(:,2),x(:,1)),grid on
这是结果
你怎么运行的呀,你没给输入参数t和x吧?
function y=ill(xx) % t,没用到
if nargin<1
xx=[0;0]; % 自己修改吧
end
a=1;b=0.3;
y=[a*xx(1)*xx(2)-b*xx(1),-a*xx(1)*xx(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
可能是matlab的toolbox读取问题,你试试下面两种方法:
1、在命令窗口输入 rehash toolboxcache
2、在matlab菜单栏找到 File-> Preferences, 点击General选项,在Toolbox path caching那里点击Update toolbox path Cache
这样可以么?