gpt4 book ai didi

julia - ODE 求解的问题

转载 作者:行者123 更新时间:2023-12-03 16:58:33 28 4
gpt4 key购买 nike

我正在尝试解决来自 DifferentialEquation 包的典型示例,
根据他们页面上的指南。
这是示例:

using DifferentialEquations
using Plots

function lorenz(t,u, du)
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))
然后我得到:

ERROR: LoadError: Parameters were indexed but the parameters are nothing. You likely forgot to pass in parameters to the DEProblem!


这里有什么问题?
提前致谢!

最佳答案

您可以尝试按照此示例进行操作,该示例基于您所做的工作:

using DifferentialEquations
using Plots

function lorenz(du,u,p,t)
du[1] = p[1]*(u[2]-u[1])
du[2] = u[1]*(p[2]-u[3]) - u[2]
du[3] = u[1]*u[2] - p[3]*u[3]
end

u0 = [1.0;0.0;0.0]
tspan = (0.0,100.0)
p = (10.0,28.0,8/3)
prob = ODEProblem(lorenz, u0, tspan,p)
sol = solve(prob)
xyzt = plot(sol, plotdensity=10000,lw=1.5)
xy = plot(sol, plotdensity=10000, vars=(1,2))
xz = plot(sol, plotdensity=10000, vars=(1,3))
yz = plot(sol, plotdensity=10000, vars=(2,3))
xyz = plot(sol, plotdensity=10000, vars=(1,2,3))
plot(plot(xyzt,xyz),plot(xy, xz, yz, layout=(1,3),w=1), layout=(2,1))

关于julia - ODE 求解的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64768728/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com