# Interpolation of Discrete 3D Vector Field

I have a vector field with discrete values and I want to interpolate these values to create a differentiable vector field.

I have matrices which give the vector values of the velocity - $vx, vy, vz$. They have dimensions of $(5,5,5)$. I put these together to get a vector field which looks like $(vx,vy,vz)$ with dimensions $(5,5,5,3)$ i.e. each coordinate has a vector at it.

But the interpolation function on this matrix doesn't seem to work.

interpolation = ListInterpolation[together]


No errors here, but when I plot it I get a blank graph, whereas from the "raw" data I get what I would expect.

All Code:

vx = ConstantArray[1, {5, 5, 5}]
vx = ConstantArray[3, {5, 5, 5}]
vy = ConstantArray[2, {5, 5, 5}]

together =
ArrayReshape[Transpose[Flatten /@ {vx, vy, vz}], {5, 5, 5, 3}]

interpolation = ListInterpolation[together]

ListVectorPlot3D[together]
VectorPlot3D[interpolation[x, y, z], {x, 1, 5}, {y, 1, 5}, {z, 1, 5}]


From ListVectorPlot: From VectorPlot3D (interpolation): • I have the same problem with a 2D vector field with data of the form: {{x,y},{vx,vy}}, namely the value of teh coordinate {x,y} where I have the vector {vx,vy}. I want to interpolate these values to create a differentiable vector field. Any help? – umby May 21 '18 at 16:48

It is certainly possible to get vectorial output from ListInterpolation. Here is a way to do it, given your original data (with typos corrected):

vx = ConstantArray[1, {5, 5, 5}];
vy = ConstantArray[3, {5, 5, 5}];
vz = ConstantArray[2, {5, 5, 5}];

together =
ArrayReshape[Transpose[Flatten /@ {vx, vy, vz}], {5, 5, 5, 3}];

interpolation =
ListInterpolation[Map[{#} &, together, {-2}], {{1, 5}, {1, 5}, {1, 5}}];

VectorPlot3D[interpolation[x, y, z], {x, 1, 5}, {y, 1, 5}, {z, 1, 5}] The result of this plot is the same as for the original field. To provide some additional guidance to ListInterpolation, I wrapped each of the vectors in a list using Map. Then I also provided the range of indices in the three coordinate directions as arguments to ListInterpolation. With this, the output of the interpolation has the correct dimensions:

interpolation The choice of arguments for ListInterpolation could of course be automated based on the dimensions of the original data array.

Interpolation only works on scalar values. So if you want to interpolate a vector field, you might have to interpolate each component individually. For an example in 2D:

vx = ConstantArray[1, {5, 5}]; vx[[3, 3]] = -1;
vy = ConstantArray[2, {5, 5}];

VectorPlot[
{ListInterpolation[vx][x, y], ListInterpolation[vy][x, y]},
{x, 1, 5}, {y, 1, 5}] • Actually, your statement about only scalar interpolation being possible is not correct, although your answer certainly would also work. See my alternative answer that shows it also works vectorially. – Jens Mar 23 '17 at 16:52