【问题标题】:Solving Systems of ODEs using Octave使用 Octave 求解 ODE 系统
【发布时间】:2018-11-08 21:24:00
【问题描述】:
>>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 并选择了正确的目录。有人会知道代码有什么问题吗?非常感谢!

【问题讨论】:

    标签: octave


    【解决方案1】:

    你似乎把你的论点反过来说。来自文档:

     -- [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”行)。

    【讨论】:

    • 感谢您的帮助。我更改了参数,但它似乎仍然不起作用。有任何想法吗?另外,我相信我们可以为函数定义自己的参数和变量,对吧?
    • “似乎不起作用”没有提供太多可使用的信息...您想用新代码和错误消息更新您的问题吗?
    • 另外,不完全是。在ode45 中使用需要遵守f 函数的规范。如果您想使用具有 不同 签名的函数,则必须首先使用匿名函数“包装”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    相关资源
    最近更新 更多