如何在Julia中传递条件内的参数?
让我们假设页面中有多个墙的反弹球的示例1:如何在Julia中传递条件内的参数?,julia,ode,Julia,Ode,让我们假设页面中有多个墙的反弹球的示例1: 并考虑条件: 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 e
并考虑条件:
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)
这里,条件(U,t,积分器)
取决于剂量时间
。因此,您也应该能够这样做:
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