gpt4 book ai didi

julia - DifferentialEquations.jl 的问题

转载 作者:行者123 更新时间:2023-12-01 23:28:34 26 4
gpt4 key购买 nike

我对 Julia 还很陌生,目前正在学习如何用它求解微分方程。我试图运行 Christopher Rackauckas 编写的简单预制代码,但出现错误。可以找到代码here .我也写在这里:

using DifferentialEquations
alpha = 0.5 #Setting alpha to 1/2
f(y,t) = alpha*y
u0 = 1.5
prob = ODEProblem(f,u0)
timespan = [0,1] # Solve from time = 0 to time = 1
sol = solve(prob,timespan) # Solves the ODE
using Plots
plot(sol) # Plots the solution using Plots.jl

我得到的错误是这样的:

LoadError: MethodError: no methof matching DiffEqBase.ODEProblem{uType,tType,isinplace,FC;MM}(::#f, ::Float64)

我也尝试运行其他类似的代码,甚至删除了 DifferentialEquations.jl -package 然后重新安装它,但没有任何改变。

有没有比我更有经验的人知道我可能做错了什么?

最佳答案

问题是博文是很久以前的了。或者至少,DifferentialEquations 1.0 在这部分有一些突破性的变化。你应该使用 the tutorial instead ,将此示例修复为最新版本。解决方案是:

using DifferentialEquations
alpha = 0.5 #Setting alpha to 1/2
f(y,t) = alpha*y
u0 = 1.5
tspan = (0.0,1.0) # Solve from time = 0 to time = 1
prob = ODEProblem(f,u0,tspan)
sol = solve(prob) # Solves the ODE
using Plots
plot(sol) # Plots the solution using Plots.jl

但现在我知道人们仍在看那篇旧帖子,我更新了它的语法以使其正确。

关于julia - DifferentialEquations.jl 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43886727/

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