>>function dxdt = fff(x,t)
%constants and parameters
u=0;
%equations
dxdt(1)=0.11*x(3)/(0.006*x(1)+x(3))*x(1)-u*x(1)/(500*x(4));
dxdt(2)=0.0055*x(3)/(0.001+x(3)*(1+10*x(3)))*x(2)-0.01*x(2)-u*x(2)/(500*x(4));
dxdt(3)=-(h1*x(1)/0.47+0.0055*x(3)/(0.001+x(3)(1+10*x(3)))*x(1)/1.2+x(1)*x(3)*0.029/(0.001+x(3)))+(1-x(3)/500)*u/x(4);
dxdt(4)=u/500;
dxdt=dxdt';
endfunction
>>[x,t]=ode45(@dxdt,[1.5 0 0 7]',[0 120])
error: x(3): out of bound 1
error: called from
dxdt at line 5 column 10
starting_stepsize at line 46 column 5
ode45 at line 192 column 25
当我执行代码时,以上错误弹出。 x0 = [1.5 0 0 7]',并且t的范围是0到120。我保存了dxdt.m并选择了正确的目录。有人会为代码有什么问题提供线索吗?非常感谢!
答案 0 :(得分:0)
您似乎在反驳您的论点。从文档中:
-- [T, Y] = ode45 (FUN, TRANGE, INIT)
FUN is a function handle, inline function, or string containing the
name of the function that defines the ODE: 'y' = f(t,y)'. The
function must accept two inputs where the first is time T and the
second is a column vector of unknowns Y.
还要注意一个事实,它期望一个“列”向量。不确定这是否重要,但是可以解释为什么它抱怨它仅具有“ 1”索引(因为您要传递的内容仅具有“ 1”行)。