1
$\begingroup$

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:

enter image description here

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!

$\endgroup$
12
  • $\begingroup$ You need to give a numerical value for v. Try newfun[1, v] and you'll why. $\endgroup$
    – Nasser
    Dec 6, 2021 at 10:00
  • $\begingroup$ Where I have to try to use newfun[1,v]? $\endgroup$ Dec 6, 2021 at 10:02
  • $\begingroup$ 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. $\endgroup$
    – Nasser
    Dec 6, 2021 at 10:05
  • $\begingroup$ 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? $\endgroup$ Dec 6, 2021 at 10:05
  • $\begingroup$ I need to have a new function in the only variable v. $\endgroup$ Dec 6, 2021 at 10:06

1 Answer 1

1
$\begingroup$

You can use Derivative to do your partial integration:

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

Visualization:

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

enter image description here

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

$\endgroup$
6
  • $\begingroup$ 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". $\endgroup$ Dec 6, 2021 at 17:37
  • $\begingroup$ 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? $\endgroup$ Dec 6, 2021 at 20:07
  • $\begingroup$ 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. $\endgroup$
    – Carl Woll
    Dec 6, 2021 at 20:13
  • $\begingroup$ I can plot 3-dimensionally the new 'g[x,y]' function, so I can't understand why 'Derivative' implies a lower limit of integration $\endgroup$ Dec 6, 2021 at 20:14
  • $\begingroup$ 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. $\endgroup$
    – Carl Woll
    Dec 6, 2021 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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