# Interpolation of 4D data

To create a table and an interpolation function of 3D data T=f(X,Y) I have the answer here: interpolation of 3D data

How to create a table/interpolation function of 4D data T=f(X,Y,R)?

If I do

dada = Flatten[Table[{x, r, t, func[x, r, t]}, {x, 0, 1}, {r, 0, 0.12}, {t, 0,
1}], 1];
intfunc=Interpolation[data];


doesn't work. func[x,r,t] is a valid function for this domain. I think it has to do with Flatten.

-
You need learn about Interpolation – Apple Aug 26 '14 at 14:22
In the same way; add a R component to your Table. – user21 Aug 26 '14 at 14:22
This doesn't work. – Luis Fernando Moura Aug 26 '14 at 14:57

## 1 Answer

An example interpolation of 4D data:

Interpolation[Join[#, {RandomReal[]}] & /@ Tuples[Range@10, 3]]


For Interpolation to treat the indexing as regular the indices must be in ascending order, with the right-hand side iterating first (e.g. {1,1,1}, {1,1,2}, {1,1,3}). Note that Tuples is automatically in the right order if the provided array is in the right order.

Edit: Your code is almost correct, except that you should Flatten to the second level, not the first. Also by default Table will use "1" as its step-size, you need to specify the step-size if the step is going to be different from 1. Note that Interpolation will throw a warning about reducing the order because you only have 2 points per dimension.

data = Flatten[Table[{{x, r, t}, RandomReal[]},
{x, 0, 1}, {r, 0, 0.12, 0.12}, {t, 0, 1}], 2];
intfunc = Interpolation@data;

-
Thanks @Guillochon. I think it isn't so easy to learn the Flatten command just reading the documentation: reference.wolfram.com/language/ref/Flatten.html – Luis Fernando Moura Aug 26 '14 at 16:02