# Numerical integration in one variable, of a multivariable interpolation function

I create the following set of data:

newmatrix = Flatten[Table[{t, v, new[t, v]}, {t, 0, 2 Pi, Pi/4}, {v, 0, 1,
0.01}], 1]


where

new[t_, v_] = t^2 + v^2


Then I defined a function that interpolate the previous data set:

newfun = Interpolation[newmatrix, Method -> "Hermite"]


I can plot it:

Now I need to integrate the interpolation function in one of the two variables like:

NIntegrate[newfun[t, v], {t, 0, 1}, AccuracyGoal -> 5]


but it doesen't work.

The error code is:

NIntegrate::inumr: The integrand <<1>> has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,0.785398}}.


Where is my error ?

Thanks for any tips and helps!

• You need to give a numerical value for v. Try newfun[1, v] and you'll why. Commented Dec 6, 2021 at 10:00
• Where I have to try to use newfun[1,v]? Commented Dec 6, 2021 at 10:02
• I mean just type newfun[1, v] before you call NIntegrate you'll see the problem. You need to have a numerical value for v inside NIntegrate call. Commented Dec 6, 2021 at 10:05
• Basically you saying that I have to create another set of data with some numerical evaluation of the previously integral for some values of v, and then I can create another interpolation function in the variable v? Commented Dec 6, 2021 at 10:05
• I need to have a new function in the only variable v. Commented Dec 6, 2021 at 10:06

You can use Derivative to do your partial integration:

g = Derivative[-1, 0][newfun];


Visualization:

Plot[g[1, x], {x, 0, 1}]


Note that using Derivative in this way implies that the lower limit of integration is at the boundary of the interpolation domain.

• It is what I need, clear! Thanks you! But now I have another question: I noticed with the method "Hermite" I can plot 3-dimensionally the new function g, but i can't with the method "Spline". Commented Dec 6, 2021 at 17:37
• Sorry, but I don't understand the use of Derivative and why you plot g[1,x], what do you mean with the "one" in first argument of the new 'g' function? Commented Dec 6, 2021 at 20:07
• Derivative[-1, 0][newfun] means integrate over the first variable starting from the beginning of the domain, in this case integrating starting at t = 0. g[1, x] means integrate up to t = 1. Commented Dec 6, 2021 at 20:13
• I can plot 3-dimensionally the new 'g[x,y]' function, so I can't understand why 'Derivative' implies a lower limit of integration Commented Dec 6, 2021 at 20:14
• g[x, y] means integrate your interpolating function from t = 0 to t = x. You can choose x to be any value in the domain of the interpolating function. Commented Dec 6, 2021 at 20:18