DifferentialEquations.jl 有问题
Trouble with DifferentialEquations.jl
我对 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 然后重新安装它,但没有任何改变。
有没有比我更有经验的人知道我可能做错了什么?
问题是博客 post 是很久以前的了。或者至少,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
但现在我知道人们还在看那个旧的 post,我更新了它的语法以使其正确。
我对 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 然后重新安装它,但没有任何改变。
有没有比我更有经验的人知道我可能做错了什么?
问题是博客 post 是很久以前的了。或者至少,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
但现在我知道人们还在看那个旧的 post,我更新了它的语法以使其正确。