如何在Julia中传递条件中的参数?

  • 本文关键字:条件 参数 Julia julia ode
  • 更新时间 :
  • 英文 :


让我们假设在页面中有多个墙壁的弹跳球的例子1:

https://diffeq.sciml.ai/stable/features/callback_functions/

并考虑条件:

function condition(out,u,t,integrator) # Event when event_f(u,t) == 0
out[1] = u[1]
out[2] = (u[3] - 10.0)u[3]
end

但是,假设我想要值"10.0"作为参数(例如,"h")。有没有办法像下面这样写?

function condition(out,u,t,integrator) # Event when event_f(u,t) == 0
out[1] = u[1]
out[2] = (u[3] - h)u[3]
end

考虑稍后在您列出的同一页面上的代码:

dosetimes = [4.0,8.0]
condition(u,t,integrator) = t ∈ dosetimes
affect!(integrator) = integrator.u[1] += 10
cb = DiscreteCallback(condition,affect!)
sol = solve(prob,Tsit5(),callback=cb,tstops=dosetimes)
plot(sol)

这里,condition(U, t, integrator)依赖于dosetimes。所以你应该可以这样做:

const h = [10.0] # h is a global const, but h[1] can be changed if needed
function condition(out,u,t,integrator) # Event when event_f(u,t) == 0
out[1] = u[1]
out[2] = (u[3] - h[1])u[3]
end

最新更新