DifferentialEquations.jl 在特定点的输出
Output from DifferentialEquations.jl at specific points
我正在尝试使用来自 Julia 的 DifferentialEquations.jl。我设法让它工作,但我想知道如何在特定时间点生成输出。文档对此并不清楚,我还没有找到一个这样做的例子。我目前使用的代码来自教程:
using DifferentialEquations
using Plots
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
u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(lorenz,u0,tspan)
sol = solve(prob)
plot(sol,vars=(1,2,3))
目前它产生了1287点,我不知道它是如何决定的。我的问题是如果我想在跨度 0 到 100 之间生成 20 个点怎么办?
The ODE tutorial section on "Controlling the Solvers" 演示了为此目的使用 saveat
。演示为:
sol = solve(prob,reltol=1e-6,saveat=0.1)
这将在您的示例中保存为 0.0、0.1...。在其下方注意到:
More generally, saveat can be any collection of time points to save at.
因此,例如,我们可以使用 save at 仅在 t=30、60 和 78 保存,如下所示:
sol = solve(prob,saveat=[30.0,60.0,78.0])
这些示例应该能为您指明正确的方向。有关详细信息,请参阅 the Output Controls section of the documentation。
我正在尝试使用来自 Julia 的 DifferentialEquations.jl。我设法让它工作,但我想知道如何在特定时间点生成输出。文档对此并不清楚,我还没有找到一个这样做的例子。我目前使用的代码来自教程:
using DifferentialEquations
using Plots
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
u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
prob = ODEProblem(lorenz,u0,tspan)
sol = solve(prob)
plot(sol,vars=(1,2,3))
目前它产生了1287点,我不知道它是如何决定的。我的问题是如果我想在跨度 0 到 100 之间生成 20 个点怎么办?
The ODE tutorial section on "Controlling the Solvers" 演示了为此目的使用 saveat
。演示为:
sol = solve(prob,reltol=1e-6,saveat=0.1)
这将在您的示例中保存为 0.0、0.1...。在其下方注意到:
More generally, saveat can be any collection of time points to save at.
因此,例如,我们可以使用 save at 仅在 t=30、60 和 78 保存,如下所示:
sol = solve(prob,saveat=[30.0,60.0,78.0])
这些示例应该能为您指明正确的方向。有关详细信息,请参阅 the Output Controls section of the documentation。