我正在学习OCTAVE,我正在尝试使用LSODE ODE求解器来集成FitzHugh–Nagumo model的版本。我的尝试看起来像这样:
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)
我已经定义的所有函数都在我在GitHub中设置的存储库中 - link。我创建了一个函数,将FHN模型的两个2D字段转换为行向量(我从examples了解到LSODE积分器使用行向量作为输入)。我收到此错误消息:
>> 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
>>
有人知道可能是什么问题吗?
答案 0 :(得分:2)
这已在http://octave.1599824.n4.nabble.com/Using-Hindmarsh-s-ODE-solver-LSODE-in-OCTAVE-td4674210.html
处得到解答然而,快速查看您的代码,您想要的系统 求解可能是一个源自a的常微分方程 pde空间离散化,即
$ dx(t)/ dt = f(x,t):= - K x(t)+ r(t)$
K是方阵(拉普拉斯算子?!),f是时间依赖的 匹配维度的功能。我希望你的系统很僵硬 (由于右侧的负拉普拉斯算术)和你 对10 ^( - 4)的错误感到满意。因此你应该适应 lsode的选项:
lsode_options("integration method","stiff"); lsode_options("absolute tolerance",1e-4); lsode_options("relative tolerance",1e-4);
然后
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
你应该利用关于雅可比df / dx的任何知识 加快计算速度。在线性ODE的情况下这是微不足道的:
f = {@(x,t) -K*x+r(t), @(x,t) -K}; % right-hand-side function.
另一方面,如果系统有额外的质量矩阵
$ M dx(t)/ dt = -K x(t)+ r(t)$
事情可能会变得更加复杂。你可能想要使用另一个 时间步进。只有当M具有完全排名然后你才能做到f = @(x,t) ( M\(-K*x+r(t)) ); % right-hand-side function
通常效率不高。
再见塞巴斯蒂安