2个问题:
- 如何在解微分方程时输出指定时刻的方程解,类似于scipy.integrate.solve_ivp里t_eval的功能?
t_eval: Times at which to store the computed solution. - 如何在解微分方程时由于满足某些条件而停止当前解方程的过程,直接出结果?
类似于scipy.integrate.solve_ivp的events.
例如:解关于某一变量的微分方程,当变量由正值变为负值时就停止计算。
2个问题:
不是很了解scipy。
第一个的话如果你只是要保存过去点的位置,而不是要求解器具体停在某个地方,设置的应为saveat。如果是要求停在某个精确地方应为tstops
文档详见https://diffeq.sciml.ai/stable/basics/common_solver_opts/#Output-Control
如果想让解一步步求解,或者停在某个位置,在某个地方修改条件,可以用Callback功能,详见
https://diffeq.sciml.ai/stable/features/callback_functions/
多谢,callback function应该能够实现event功能。
saveat这个我知道,但它是间隔指定的时间保存,我希望在对数空间里线性间隔保存,这个有什么办法实现吗?
并不是只能指定间隔。“The solver will save at each of the timepoints in this array in the most efficient manner available to the solver. ”
julia> function lorenz!(du,u,p,t)
du[1] = 10.0*(u[2]-u[1])
du[2] = u[1]*(28.0-u[3]) - u[2]
du[3] = u[1]*u[2] - (8/3)*u[3]
end
julia> u0 = [1.0;0.0;0.0]
julia> tspan = (0.0,100.0)
julia> prob = ODEProblem(lorenz!,u0,tspan)
julia> sol = solve(prob, saveat=[0.,1.,10.,100.])
retcode: Success
Interpolation: 1st order linear
t: 4-element Array{Float64,1}:
0.0
1.0
10.0
100.0
u: 4-element Array{Array{Float64,1},1}:
[1.0, 0.0, 0.0]
[-9.395644820158797, -9.093947230946473, 28.553962333688983]
[-5.694805426158249, -5.433239308688495, 24.12821685769235]
[9.97537965430362, 15.143884806010783, 21.00643286956427]
谢谢,之前没仔细看说明。