OrdinaryDiffEq vcat to make du

This is creating a new vector, not modifying du. It would need to be du .= vcat(dx1,dx2), though then you’d be allocating. The more efficient one is:

function f(du,u,p,t)

    x1 = u[1]
    x2 = u[2]
    dx1 = x2
    dx2 = -x1
    du[1] = dx1
    du[2] = dx2
    return nothing
end
1 Like