Tricky interpolation issue

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.

Your error

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

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.

1 Like