# No method matching getindex() using ODEProblem

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 = (qmax-F(3))
out = F(2)
out = 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)

# 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)

QL = 0
QR = 1e+15

for iter = 1:50
F0 = (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

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

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, `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`

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

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

``````MethodError: no method matching +(::Float64, ::Vector{Float64})
`a .+ b` when it’s between a Float64 and a Vector{Float64} to do it element-wise.