首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DifferentialEquations.jl中回调函数的选择问题

DifferentialEquations.jl中回调函数的选择问题
EN

Stack Overflow用户
提问于 2020-08-11 19:05:20
回答 1查看 203关注 0票数 2

我有一个对象,当它达到阈值时,它将进入一个静默期,我使用一个参数(我称之为ode_status)在1到0之间翻转以确定是否执行ODE。

阈值由ContinuousCallback实现。

代码语言:javascript
复制
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

代码语言:javascript
复制
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。

我想我滥用了这些回调函数。有人能告诉我怎么解决这个问题吗?提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-21 12:22:42

这是因为下一步并不完全是在5秒之后。请记住,DiscreteCallback只在步长时间触发,所以您需要插入一个tstop来告诉它在将来完全停止5秒。

代码语言:javascript
复制
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)
end
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63364779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档