# 3D interpolation providing derivatives

I am trying to interpolate 3D data by also providing the 1st order derivaives in all directions, i.e., besides (x,y,z,f), I also have df/dx, df/dy and df/dz.

According to the documentation I should do something like

Interpolation[{{{x1,…},f1,df1,…},…}]

which I am doing as follows (MWE):

x = Table[i, {i, 0, 10}];
y = Table[i, {i, 0, 10}];
z = Table[i, {i, -3, 3}];
xyzList = Flatten[Table[{x[[i]], y[[j]], z[[k]]}, {i, 1, Length[x]}, {j, 1,Length[y]}, {k, 1,Length[z]}], 2];

f = RandomReal[{0, 1}, {11, 11, 7}];
dfdx = RandomReal[{0, 1}, {11, 11, 7}];
dfdy = RandomReal[{0, 1}, {11, 11, 7}];
dfdz = RandomReal[{0, 1}, {11, 11, 7}];

listToInterp = Thread[{xyzList, Flatten[f, 2], Flatten[dfdx, 2], Flatten[dfdy, 2], Flatten[dfdz, 2]}];

Interpolation[listToInterp]


and I get the error

For 3D data, the gradient at each point should be given as a list. You can process your listToInterp to get an input list with the correct structure:

listToInterp2 = {#, #2, {##3}} & @@@ listToInterp;

iF = Interpolation[listToInterp2]


iF[1, 2, 1]

0.1172247964


An alternative, more streamlined, way to get an input list:

xyz = Tuples[{Range[0, 10], Range[0, 10], Range[-3, 3]}];

vals = RandomReal[1, {11 11 7, 1}];

grad = RandomReal[1, {11 11 7, 1, 3}];

interpolationInput = Join[List /@ xyz, vals, grad, 2];

iF = Interpolation[interpolationInput]