# Tricky interpolation issue

**URL:** <https://discourse.julialang.org/t/tricky-interpolation-issue/90142>\
**Category:** General Usage\
**Tags:** interpolations\
**Created:** [November 12, 2022, 12:55am UTC](https://discourse.julialang.org/t/tricky-interpolation-issue/90142 "2022-11-12T00:55:20Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [November 12, 2022, 9:33am UTC](https://discourse.julialang.org/t/tricky-interpolation-issue/90142/3 "2022-11-12T09:33:46Z")

</div>

First a general note:  
`nkp` and `nk` are not defined inside the function. My guess is, you are using global vars here, this is not recommended. Try to use them as parameters to the function. This would also help for a [MWE](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757).

Your error

> [@ejlongman](#):
>
> attempt to access 11-element Vector{Float64} at index [12]

results from accessing `short_grid[up]` and `short_grid[down]`. From your code it is not clear that `up` and `down` are really restricted to the allowed indices from 1 to 11.  
For an example with `nk=11` and `nkp=20` you get in the loop at the last `i=nkp`:

```julia
julia> nk=11
11

julia> nkp=20
20

julia> i=nkp
20

julia> down = Int(floor((nk-1.0)*(i-1.0)/(nkp-1.0))+1)
11

julia> up = down+1
12

```

Now it is clear that `short_grid[up]` should fail.

Perhaps it is already solved with

```julia
for i in 1:(nkp-1)

```

but that is just guessing.

To give you some alternative we need to know what exactly you try to do. Best would be a MWE with some example input and your desired output and some explanations on the how and why the desired result should be achieved.

---

_[View the full topic](https://discourse.julialang.org/t/tricky-interpolation-issue/90142)._
