1
$\begingroup$

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:

enter image description here

From VectorPlot3D (interpolation):

enter image description here

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – umby May 21 '18 at 16:48
2
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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

1

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Jens Mar 23 '17 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.