# Solving a system of differential equations with DifferentailEqations.jl

**URL:** <https://discourse.julialang.org/t/solving-a-system-of-differential-equations-with-differentaileqations-jl/13406>\
**Category:** Numerics\
**Tags:** diffeq\
**Created:** [August 13, 2018, 8:42pm UTC](https://discourse.julialang.org/t/solving-a-system-of-differential-equations-with-differentaileqations-jl/13406 "2018-08-13T20:42:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OvidiusCicero](https://avatars.discourse-cdn.com/v4/letter/o/73ab20/32.png) [@OvidiusCicero](https://discourse.julialang.org/u/OvidiusCicero)\
**Post date:** [August 13, 2018, 8:42pm UTC](https://discourse.julialang.org/t/solving-a-system-of-differential-equations-with-differentaileqations-jl/13406/1 "2018-08-13T20:42:22Z")

</div>

Hello there

when I try to solve a system of ordinary differential equations with the following code:

```
using DifferentialEquations

function dgl(du,u,p,t)
	du[1] = u[3]
	du[2] = u[4]
	du[3] = -sqrt(u[4]^2+u[5]^2)*u[3]
	du[4] = -sqrt(u[4]^2+u[5]^2)*u[4] - 1
end

u0 = [0.0; 0.0; 100.0; 100.0]
prob = ODEProblem(dgl, (0.0, 10.0), u0)
#sol = solve(prob)

```

I get this error I can’t grasp:

```
MethodError: Cannot `convert` an object of type Array{Float64,1} to an object of type Tuple{Float64,Float64}
This may have arisen from a call to the constructor Tuple{Float64,Float64}(...),
since type constructors fall back to convert methods.

Stacktrace:
 [1] (::DiffEqBase.##call#174#178)(::Void, ::Void, ::UniformScaling{Int64}, ::Type{DiffEqBase.ODEProblem{true,tType,isinplace,P,F,J,C,MM,PT} where PT where MM where C where J where F where P where isinplace where tType}, ::Function, ::Tuple{Float64,Float64}, ::Array{Float64,1}, ::Void, ::DiffEqBase.StandardODEProblem) at /home/christian/.julia/v0.6/DiffEqBase/src/problems/ode_problems.jl:23
 [2] DiffEqBase.ODEProblem{true,tType,isinplace,P,F,J,C,MM,PT} where PT where MM where C where J where F where P where isinplace where tType(::Function, ::Tuple{Float64,Float64}, ::Array{Float64,1}, ::Void) at /home/christian/.julia/v0.6/DiffEqBase/src/problems/ode_problems.jl:18
 [3] #ODEProblem#182(::Array{Any,1}, ::Type{T} where T, ::Function, ::Tuple{Float64,Float64}, ::Array{Float64,1}, ::Void) at /home/christian/.julia/v0.6/DiffEqBase/src/problems/ode_problems.jl:33
 [4] DiffEqBase.ODEProblem(::Function, ::Tuple{Float64,Float64}, ::Array{Float64,1}) at /home/christian/.julia/v0.6/DiffEqBase/src/problems/ode_problems.jl:32
 [5] execute_request(::ZMQ.Socket, ::IJulia.Msg) at /home/christian/.julia/v0.6/IJulia/src/execute_request.jl:180
 [6] (::Compat.#inner#14{Array{Any,1},IJulia.#execute_request,Tuple{ZMQ.Socket,IJulia.Msg}})() at /home/christian/.julia/v0.6/Compat/src/Compat.jl:332
 [7] eventloop(::ZMQ.Socket) at /home/christian/.julia/v0.6/IJulia/src/eventloop.jl:8
 [8] (::IJulia.##15#18)() at ./task.jl:335

```

​I feel like it must be something very stupid because my code is very similiar to the example from the docs

Thanks for any help

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [August 13, 2018, 8:59pm UTC](https://discourse.julialang.org/t/solving-a-system-of-differential-equations-with-differentaileqations-jl/13406/2 "2018-08-13T20:59:05Z")

</div>

You just switched the `ODEProblem` constructor arguments. Should be `prob = ODEProblem(dgl, u0, (0.0, 10.0))`. By the way, your `u0` has four elements, but you’re trying to access the fifth in `dgl`.

---

<div class="post-metadata">

**Author:** ![OvidiusCicero](https://avatars.discourse-cdn.com/v4/letter/o/73ab20/32.png) [@OvidiusCicero](https://discourse.julialang.org/u/OvidiusCicero)\
**Post date:** [August 13, 2018, 9:27pm UTC](https://discourse.julialang.org/t/solving-a-system-of-differential-equations-with-differentaileqations-jl/13406/3 "2018-08-13T21:27:08Z")

</div>

thank you so much – I felt really stupid  
also thanks for the hint with the fifth element but it arised from reducing the example
