# No method matching getindex() using ODEProblem

**URL:** https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361
**Category:** General Usage
**Tags:** faq, ode, error-message
**Created:** [May 18, 2021, 1:31pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361 "2021-05-18T13:31:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Fabio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabio/32/21533_2.png) [@Fabio](https://discourse.julialang.org/u/Fabio)
#### Post date: [May 18, 2021, 1:31pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361/1 "2021-05-18T13:31:15Z")

</div>

Hey there,

I am very new to Julia and I am working on an ODE Problem. Basically this is my set-up:

> ```
> etaspan = (0.0, 1.0)
> F0 = [1, -1e+10, q_, 0] 
> 
> function eventfcn(vcondition, value, eta, integrator)
> out[1] = (qmax-F(3))   
> out[2] = F(2)
> out[3] = F(4)
> end
> 
> function affect!(integrator, idx)
> if (idx == 1 | idx == 2 | idx == 3)
> affect!(integrator) = terminate!(integrator)
> end
> end
> 
> cb = VectorContinuousCallback(eventfcn,affect!,3)    
> 
> # odefun(eta,f) will be a vector containing 4 partial derivatives (ODEs), that I
> # calculate before with the function fnct
> odefun(eta, f) = fnct(eta, f, r, rho, a, a_, delta, delta_, sigma)[1]
> 
> # dyn will be a vector containing all dynamic parameters. I also get them through function fnct
> dyn(eta, f) = fnct(eta, f, r, rho, a, a_, delta, delta_, sigma)[2]
> 
> QL = 0
> QR = 1e+15
> 
> for iter = 1:50
> F0[4] = (QL+QR)/2
> prob = ODEProblem(odefun, F0, etaspan, dyn)
> sol = solve(prob, Tsit5(), callback = cb, RelTol = 1e-08, abstol = 1e-10)
> end
> 
> ```

However, when trying to run all of this, I get the following error message:

> MethodError: no method matching getindex(::typeof(dyn), ::Int64)

As far as I understood, the ODEProblem will at one point call function getindex, but I don’t know why it doesn’t work. Any help would be highly appreciated! \<3

---

<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 18, 2021, 1:58pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361/2 "2021-05-18T13:58:43Z")

</div>

> [@Fabio](#):
>
> ```julia
> # dyn will be a vector containing all dynamic parameters. I also get them through function fnct
> dyn(eta, f) = fnct(eta, f, r, rho, a, a_, delta, delta_, sigma)[2]
> 
> ```

That’s not a vector, it’s a function.

---

<div class="post-metadata">

### Author: ![Fabio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabio/32/21533_2.png) [@Fabio](https://discourse.julialang.org/u/Fabio)
#### Post date: [May 18, 2021, 3:27pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361/3 "2021-05-18T15:27:56Z")

</div>

Hey Chris. It’s actually a vector. The function “fnct” gives me 2 vectors as an output. dyn will be the second of the 2. I just didn’t want to include the “fnct” function cause it would be too long and it’s not necessary for the purpose here…

---

<div class="post-metadata">

### Author: ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)
#### Post date: [May 18, 2021, 3:40pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361/4 "2021-05-18T15:40:23Z")

</div>

No, `dyn` is function that takes two arguments `eta` and `f`. This is how you define it.

Are you trying to have time-dependent parameters? If so, you should shift the time dependence into `odefun`

---

<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 18, 2021, 5:37pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361/5 "2021-05-18T17:37:34Z")

</div>

> [@Fabio](#):
>
> Hey Chris. It’s actually a vector. The function “fnct” gives me 2 vectors as an output. dyn will be the second of the 2. I just didn’t want to include the “fnct” function cause it would be too long and it’s not necessary for the purpose here…

No, it’s not a vector. If you wanted a vector you would write:

```julia
dyn = fnct(eta, f, r, rho, a, a_, delta, delta_, sigma)[2]

```

and that’s exactly your error.

---

<div class="post-metadata">

### Author: ![Fabio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabio/32/21533_2.png) [@Fabio](https://discourse.julialang.org/u/Fabio)
#### Post date: [May 18, 2021, 7:54pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361/6 "2021-05-18T19:54:27Z")

</div>

Hey @ChrisRackauckas and @skleinbo. Thank you very much for your answers.

Indeed, the getindex() error message disappeared once I defined dyn as a vector. But from that I got some other problems and they related to what you mentioned @skleinbo. Function fnct(eta, f, …) does 2 things. It calculates fp, the vector of derivatives and it will update the parameters at every iteration, which is what you @skleinbo were referring to (just that in my model, everything evolves with eta rather than with time).

What I can’t figure out is how to integrate these dynamic parameters in my model. This is what happened when I defined dyn as a global inside the fnct function (instead of returning it):

> ```
> MethodError: no method matching +(::Float64, ::Vector{Float64}) 
> For element-wise addition, use broadcasting with dot syntax: scalar .+ array
> 
> ```

Thanks again !

---

<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 18, 2021, 8:18pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex-using-odeproblem/61361/7 "2021-05-18T20:18:44Z")

</div>

> [@Fabio](#):
>
> What I can’t figure out is how to integrate these dynamic parameters in my model. This is what happened when I defined dyn as a global inside the fnct function (instead of returning it):

`a .+ b` when it’s between a Float64 and a Vector{Float64} to do it element-wise.
