4

我對Julia很新,我目前正在學習如何用它來求解微分方程。我試圖通過Christopher Rackauckas運行一個簡單的預製代碼,但我得到了一個錯誤。代碼可以找到here。我在這裏也寫:DifferentialEquations.jl問題

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和然後重新安裝它,但沒有任何改變。

任何更有經驗的人有一個想法我可能做錯了什麼?

回答

5

問題在於博客文章是相當長的一段時間。或者至少,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 

但現在我知道人們仍在看那個舊帖子,我更新了它的語法是正確的。

+0

謝謝克里斯!現在代碼正常工作。 – maikkirapo