Search code examples
juliaode

Julia ODE package example fail


I wanted to use Julia ODE package. I saw this example online:

tspan = [0 2*pi()] y_0 = [1 0]' F = (t, y) -> [0 1; -1 0]*y ode23(F, tspan, y_0)

(source: https://github.com/JuliaLang/julia/blob/84757050b26ed549b9aee77ac7c204d9963285a2/j/ode.j)

Yet when I run it I get the following error:

ERROR: DimensionMismatch("*")
 in generic_matmatmul! at linalg/matmul.jl:372
 in * at linalg/matmul.jl:117
 in anonymous at none:1
 in ode23 at /home/rm/.julia/v0.4/ODE/src/ODE.jl:67

A simple example would help.


Solution

  • The example you linked to is from 2011. The code has at least two errors. One, calling pi() is incorrect; pi is now a constant. The second is the code moved from base to the ODE package. A working example (using Julia 0.4) can be seen at:

    https://github.com/JuliaLang/ODE.jl/blob/master/src/ODE.jl#L36-39

    using ODE
    tspan = [0, 2*pi]
    y0 = [1, 0]
    F = (t, y) -> [0 1; -1 0]*y
    ode23(F, tspan, y0)
    

    Note that I know nothing about solving these types of equations, I just know some of the history of moving things from base into separate packages.