简体   繁体   English

Rs中的Lsoda函数

[英]Lsoda function in R

To calculate the behaviour of my system of 2 equations, I use the lsoda function in R. The parameters a varies over time : is 1 when time is even and 0 otherwise. 要计算2个方程式系统的行为,我在R中使用了lsoda函数。参数a随时间变化:当时间为偶数时为1,否则为0。 Here is a minimal reproducible example : 这是一个最小的可重现示例:

mo=function(t,x,m){
if(t%%2==0){
   a=m
}else{
   a=0
}
dx=rep(0,2)
dx[1]=-a*x[1]
dx[2]=a*x[1]
res=dx
return(list(dx))
}
xs=c(10,0)
ti=1:100
m=1
data1=as.data.frame(lsoda(xs,ti,mo,m))

The problem is that when you investigate the results, you see that x[1] remains at 10 while x[2] remains at 0, meaning that lsoda always take the value 0 for a (and never 1). 问题在于,当您调查结果时,您会看到x [1]保持为10,而x [2]保持为0,这意味着lsoda对于a始终取值为0(从不取1)。 Is it an issue with the modulo? 模数有问题吗?

lsoda chooses its own internal time step, so there is no guarantee that t%%2 == 0 will ever be true even if you ask for output when this condition is true (eg, t=2 ). lsoda选择自己的内部时间步长,因此即使在此条件为真(例如t=2 )时要求输出,也无法保证t%%2 == 0将永远为真。 My understanding is that lsoda will interpolate between solution times to get output at the times requested by the user and not necessarily solve the model at those times. 我的理解是, lsoda将在解决方案时间之间进行插值,以在用户请求的时间获得输出,而不必在那些时间求解模型。 As a rule of thumb, hard temporal or spatial interfaces are a Bad Thing™ when it comes to numerical ODE solvers. 根据经验,对于数字ODE求解器,硬的时间或空间接口是Bad Thing™。

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

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