简体   繁体   English

在OCTAVE中使用Hindmarsh的ODE求解器LSODE

[英]Using Hindmarsh’s ODE solver LSODE in OCTAVE

I am learning OCTAVE, and I am trying to use LSODE ODE solver to integrate a version of FitzHugh–Nagumo model . 我正在学习OCTAVE,并且正在尝试使用LSODE ODE求解器集成FitzHugh–Nagumo模型的版本。 My attempt looks like this: 我的尝试如下所示:

time = linspace(0,200,1000);
u0 = rand(32,32);
v0 = rand(32,32);

vec_u0 = reshape(u0,[1,size(u0)(1)*size(u0)(2)]);
vec_v0 = reshape(v0,[1,size(v0)(1)*size(v0)(2)]);
vec_FHN0 = horzcat(vec_u0,vec_v0);

FHN = lsode("FHN_eq_vec", vec_FHN0, time);
FHN(end)

where all of the functions I have defined are in the repository I have set in GitHub - link . 我定义的所有功能都在我在GitHub- link中设置的存储库中。 I have created a function that transform the two 2D fields of the FHN model into a row vector (as I understand from the examples here the LSODE integrator use row vector as input). 我创建了一个将FHN模型的两个2D字段转换为行向量的函数(据我从此处的示例了解,LSODE积分器使用行向量作为输入)。 I got this error message: 我收到此错误消息:

>> fhn_integrate_lsode
warning: non-integer range used as index
warning: called from
    FHN_eq_vec at line 3 column 7
    fhn_integrate_lsode at line 9 column 5
error: reshape: can't reshape 0x1 array to 1x1 array
error: called from
    FHN_eq_vec at line 4 column 3
    fhn_integrate_lsode at line 9 column 5
error: lsode: evaluation of user-supplied function failed
error: called from
    fhn_integrate_lsode at line 9 column 5
error: lsode: inconsistent sizes for state and derivative vectors
error: called from
    fhn_integrate_lsode at line 9 column 5
>>

Someone knows what could be the problem? 有人知道可能是什么问题吗?

This has been answered at http://octave.1599824.n4.nabble.com/Using-Hindmarsh-s-ODE-solver-LSODE-in-OCTAVE-td4674210.html 可以在http://octave.1599824.n4.nabble.com/Using-Hindmarsh-s-ODE-solver-LSODE-in-OCTAVE-td4674210.html中得到解答

However, looking quickly at your code, the system that you want to solve is probably an ordinary differential equation stemming from a pde space discretization, ie, 但是,快速查看您的代码,您想要解决的系统可能是源自pde空间离散化的普通微分方程,即

$dx(t)/dt = f(x,t) := -K x(t) + r(t)$ $ dx(t)/ dt = f(x,t):= -K x(t)+ r(t)$

with K being a square matrix (Laplacian?!) and fa time-dependent function of matching dimension. 其中K是一个方阵(Laplacian ?!),并且是与时间相关的匹配维度的函数。 I expect that your system is stiff (due to the negative Laplacian on the right-hand side) and that you are happy with errors in the order of 10^(-4). 我希望您的系统是坚固的(由于右侧为负Laplacian),并且您对10 ^(-4)左右的错误感到满意。 Thus you should adapt the options of lsode: 因此,您应该调整lsode的选项:

 lsode_options("integration method","stiff"); lsode_options("absolute tolerance",1e-4); lsode_options("relative tolerance",1e-4); 

Then 然后

 T = 0:1e-2:1; % time vector K = sprandsym(32,1)+eye(32); % symmetric stiffness matrix x0 = rand(32,1); % initial values r = @(t) rand(32,1)*sin(t); % excitation vector f = @(x,t) (-K*x+r(t)); % right-hand-side function x=lsode (f, x0, T); % get solution from lsode 

You should exploit any knowledge on the Jacobian df/dx since this will speed up computations. 您应该利用有关Jacobian df / dx的任何知识,因为这将加快计算速度。 It's trivial in the case of linear ODE: 对于线性ODE而言,这是微不足道的:

 f = {@(x,t) -K*x+r(t), @(x,t) -K}; % right-hand-side function. 

On the other hand, if the system has an additional mass matrix 另一方面,如果系统具有附加质量矩阵

$M dx(t)/dt = -K x(t) + r(t)$ $ M dx(t)/ dt = -K x(t)+ r(t)$

things might become more complicated. 事情可能变得更加复杂。 You probably want to use another time stepper. 您可能想使用另一个时间步进器。 Only if M has full rank then you could do 只有M拥有全职才能做到

 f = @(x,t) ( M\\(-K*x+r(t)) ); % right-hand-side function 

which is typically not very efficient. 这通常不是很有效。

Bye Sebastian 再见塞巴斯蒂安

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM