我有一个对象,当它达到阈值时,它将进入一个静默期,我使用一个参数(我称之为ode_status)在1到0之间翻转以确定是否执行ODE。
阈值由ContinuousCallback实现。
fucntion condition(u, t, integrator)
u[1] - threshold
end
function affect!(integrator)
integrator.p[1] = 0 # integrator.p[1] represents ode_status
flip_back_time[1] = integrator.t + 5 # define silence period = 5s
end
ContinuousCallback(condition, affect!)接下来,我想在5s之后回滚ode_status,所以我使用DiscreteCallback。
function condition(u, t, integrator)
integrator.p[1] == 0 &&
integrator.t >= flip_back_time[1]
end
function affect!(integrator)
integrator.p[1] = 1
end
DiscreteCallback(condition, affect!)然而,结果却不是我想的那样。ode_status倒车的时间并不完全是在5s之后。是在5.107.或者是另一次审判中的5.879。
我想我滥用了这些回调函数。有人能告诉我怎么解决这个问题吗?提前感谢!
发布于 2021-05-21 12:22:42
这是因为下一步并不完全是在5秒之后。请记住,DiscreteCallback只在步长时间触发,所以您需要插入一个tstop来告诉它在将来完全停止5秒。
function affect!(integrator)
integrator.p[1] = 0 # integrator.p[1] represents ode_status
flip_back_time[1] = integrator.t + 5 # define silence period = 5s
add_tstop!(integrator,integrator.t + 5)
endhttps://stackoverflow.com/questions/63364779
复制相似问题