# Derivative of a 3D Interpolated function

I cannot get the partial derivative of a set of data. I managed to get the accurate interpolation, but I cannot evaluate its derivatives.

Here are my details:

data = Import["data.dat"];

The data set looks like this:

In[]=
data[[38;;49]]

Out[]=
{
{2, 38, -0.000307893533656},
{2, 39, -0.000307922246488},
{2, 40, -0.000307952337061},
{3, 0, -0.000461750353095},
{3, 1, -0.000462600240141},
{3, 2, -0.000463450127186},
{3, 3, -0.000464294338731},
{3, 4, -0.000464294338731}
}

The 3D Interpolation looks good:

pot = Interpolation[data]

And the Plot3D does too:

ListPlot3D[data, ColorFunction -> "SouthwestColors"]

There is a slight change along y (unnoticeable from Plot3D), I want to get the derivative for this function (which is along y):

Plot[ pot[50, y], {y, 0, 40} ]

When I use Derivative I get this, unable to even extract a value:

pot'[50, y]
pot'[50,3]

Not getting a function at all...

Plot[pot'[50, y], {y, 0, 40}]

What is the smart way to get the gradient of the 3D interpolated function? I also tried 'Gradient' without success:

VectorPlot[Gradient[pot[x, y]], {x, 0, 100}, {y, 0, 40}]

What must I do?

You can use Derivative[0, 1][int] to get the first derivative of int with respect to your second variable $$y$$.

To illustrate, let's create some data and interpolate:

data = Table[{x, y, Sin[x] + 2 y}, {x, 0., 10.}, {y, 0., 10.}] ~ Flatten ~ 1;
int = Interpolation[data];

Plot3D[int[x, y], {x, 0, 10}, {y, 0, 10}]

Then obtain the first derivative with respect to x vs. y respectively, and compare them with he expected values (i.e. Cos[x] and $$2$$, respectively):

Plot[
{
Derivative[1, 0][int][x, 3],
Cos[x]
},
{x, 0, 10}
]

Note that the jumps in the interpolation above are due to the relatively coarse grid on which the interpolation was carried out (i.e. with spacings of only 1 unit). This doesn't matter much here since it's just a made-up example; indeed, in a way it helps to show the two functions separately.

Plot[
{
Derivative[0, 1][int][Pi, y],
2
},
{y, 0, 10}
]

• Incredible, very illustrative example. Appreciate your time! – Joshua Salazar Jan 5 at 17:31
• @Joshua Glad to help! – MarcoB Jan 5 at 17:34