# BoundsError trying to solve DDEProblem

**URL:** <https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441>\
**Category:** New to Julia\
**Created:** [May 21, 2022, 10:21pm UTC](https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441 "2022-05-21T22:21:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Achraf\_el\_fadli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achraf_el_fadli/32/36477_2.png) [@Achraf\_el\_fadli](https://discourse.julialang.org/u/Achraf_el_fadli)\
**Post date:** [May 21, 2022, 10:21pm UTC](https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441/1 "2022-05-21T22:21:02Z")

</div>

function f(du,u,h,p,t)  
k1,k2,tau=p  
hist=h(p,t-tau)[0]  
du[0]=u0  
end  
h(p,t)=ones(1)  
tau=7  
lags=[tau]  
k1=0.5;k2=0.1  
p=k1,k2,tau  
span=(0.0,10.0)  
u0=[1.0]  
prob = DDEProblem(f,u0,h,span,p; constant\_lags=lags)  
sol=solve(prob)  
plot(sol)  
BoundsError: attempt to access 1-element Vector{Float64} at index [0]  
Stacktrace:

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [May 21, 2022, 10:29pm UTC](https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441/2 "2022-05-21T22:29:28Z")

</div>

> [@Achraf\_el\_fadli](#):
>
> du[0]=u0

I’m guessing this line is the problem since Julia is 1-based indexed.

---

<div class="post-metadata">

**Author:** ![Achraf\_el\_fadli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achraf_el_fadli/32/36477_2.png) [@Achraf\_el\_fadli](https://discourse.julialang.org/u/Achraf_el_fadli)\
**Post date:** [May 21, 2022, 10:45pm UTC](https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441/3 "2022-05-21T22:45:23Z")

</div>

then what should i do

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 21, 2022, 11:50pm UTC](https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441/4 "2022-05-21T23:50:42Z")

</div>

Replace the zeros with ones…

---

<div class="post-metadata">

**Author:** ![FrancisKing](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/francisking/32/24966_2.png) [@FrancisKing](https://discourse.julialang.org/u/FrancisKing)\
**Post date:** [May 22, 2022, 8:53am UTC](https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441/5 "2022-05-22T08:53:45Z")

</div>

You can change the indexing so that arrays start at zero, but this can cause problems as can be seen in a recent thread - far too much library code assumes that arrays start at index one.

The style with which you write code is not best practice. Because Julia has an ‘end’ keyword you don’t need to indent the code as with Python, nevertheless it is a good thing to do. It makes is easier to see how the code execution will flow.

---

<div class="post-metadata">

**Author:** ![Achraf\_el\_fadli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achraf_el_fadli/32/36477_2.png) [@Achraf\_el\_fadli](https://discourse.julialang.org/u/Achraf_el_fadli)\
**Post date:** [May 22, 2022, 12:47pm UTC](https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441/6 "2022-05-22T12:47:17Z")

</div>

using DifferentialEquations, Plots  
function f(du, u, h, p, t)  
✌ = u  
k1, k2, τ = p  
⌛ = h(p, t - τ,idxs=1)  
du[1] = d​:v: = ✌(1 - ✌ - k1 \* ✌ - k2)

end

u0 = 1.0  
τ = 7  
h(p, t,idxs=1) = 1.0  
p = 0.7, 0.5, 7  
tspan = (0.0, 10.0)  
prob = DDEProblem(f, u0, h, p, canstant\_lag = [τ])  
as a message error  
**MethodError: no method matching promote\_tspan(::Tuple{Float64, Float64, Int64})**

**Closest candidates are:  
promote\_tspan(::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any) at C:\Users\ACHRAF ELFADLI.julia\packages\DiffEqBase\foWeO\src\init.jl:3  
promote\_tspan(!Matched::Tuple{T, S}) where {T, S} at C:\Users\ACHRAF ELFADLI.julia\packages\SciMLBase\r3XzZ\src\problems\problem\_utils.jl:7  
promote\_tspan(!Matched::Number) at C:\Users\ACHRAF ELFADLI.julia\packages\SciMLBase\r3XzZ\src\problems\problem\_utils.jl:8  
…**

in eval at base\boot.jl:373

in top-level scope at untitled:16

in at SciMLBase\r3XzZ\src\problems\dde\_problems.jl:240

in var"#DDEProblem#301" at SciMLBase\r3XzZ\src\problems\dde\_problems.jl:240

in at SciMLBase\r3XzZ\src\problems\dde\_problems.jl:243

in var"#DDEProblem#302" at SciMLBase\r3XzZ\src\problems\dde\_problems.jl:243

in at SciMLBase\r3XzZ\src\problems\dde\_problems.jl:222

in at SciMLBase\r3XzZ\src\problems\dde\_problems.jl:222

in at SciMLBase\r3XzZ\src\problems\dde\_problems.jl:222

it still don’t working

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 22, 2022, 1:30pm UTC](https://discourse.julialang.org/t/boundserror-trying-to-solve-ddeproblem/81441/7 "2022-05-22T13:30:08Z")

</div>

> [@Achraf\_el\_fadli](#):
>
> prob = DDEProblem(f, u0, h, p, canstant\_lag = [τ])

It says your `tspan` is wrong because you didn’t pass it to the problem constructor.

prob = DDEProblem(f, u0, h, tspan, p, canstant\_lag = [τ])
