Search code examples
juliadifferential-equationsdifferentialequations.jl

Trouble with DifferentialEquations.jl


I'm quite new to Julia and I'm currently learning how to solve differential equations with it. I tried to run a simple pre-made code by Christopher Rackauckas, but I got an error. The code can be found here. I will also write it 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

And the error I'm getting looks like this:

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

I also tried to run other similar codes and even removed the DifferentialEquations.jl -package and then reinstalled it, but nothing changed.

Anyone more experienced having an idea what I might be doing wrong?


Solution

  • The issue is that blog post is from quite a long time ago. Or at least, DifferentialEquations 1.0 had a few breaking changes in this part. You should use the tutorial instead, which fixes this example to the newest version. The solution is:

    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
    

    But now that I know people are still looking at that old post, I updated its syntax to be correct.