# Integrating an interpolating function

I have been using the following NDEigensystem command to generate the eigenfunctions of the laplacian with a square domain:

𝒟 = Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]

{vals, funs} =
NDEigensystem[
{-Laplacian[u[x, y], {x, y}], DirichletCondition[u[x, y] == 0, True]},
u[x, y], {x, y} ∈ 𝒟, 4];


However, I am trying to compute the following integral over $D$, where funs[[3]] is the third eigenfunction given by NDEigensystem:

$\qquad \int_{𝒟}\mbox{funs[[3]]}\cdot \mbox{funs[[3]]}$

My guess was:

NIntegrate[Dot[funs[[3]], funs[[3]]], {x, y} ∈ 𝒟]


but this doesn't return a numerical value for me. I would be grateful if somebody could give me a working code for the integral.

• I believe that the funs[[3]] is a scalar value and thus Dot is not the correct call. You may just be looking to multiply funs[[3]]*funs[[3]] inside the argument of NIntegrate – leibs Mar 11 '16 at 21:04
• Thanks for your prompt reply! this is Interesting; it returns the value 1 which sounds good to me. However, it does give me the following error: "the global error of the strategy GlobalAdaptive has increased more \ than 2000 times. The global error is expected to decrease \ monotonically after a number of integrand evaluations. Suspect one of \ the following: the working precision is insufficient for the \ specified precision goal; the integrand is highly oscillatory or it \ is not a (piecewise) smooth function; or the true value of the \ integral is 0. – Mr S 100 Mar 11 '16 at 21:16
• Increasing the value of the GlobalAdaptive option \ MaxErrorIncreases might lead to a convergent numerical integration. \ NIntegrate obtained 1. and 1.16566*10^-6 for the integral and error \ estimates." – Mr S 100 Mar 11 '16 at 21:16
• Yeah, I see these sort of warnings a lot. Someone more skilled with the inner workings of NIntegrate could probably give you some options to set. I tend to prefer, for simple functions like this, using my own numerical integration scheme. See my post here: mathematica.stackexchange.com/questions/41212/… – leibs Mar 11 '16 at 22:23
• Try to integrate over the ElementMesh from the InterpolatingFunction and see if that helps. – user21 Mar 11 '16 at 23:23

*[Updated after reading @user21's comment. My original approach was equivalent, but this is more direct.]

Since NDEigensystem returns an interpolation over an ElementMesh, it seems appropriate to integrate over it.

reg = Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}];
{vals, funs} = NDEigensystem[{-Laplacian[u[x, y], {x, y}],
DirichletCondition[u[x, y] == 0, True]}, u, {x, y} ∈ reg, 4];

NIntegrate[funs[[3]][x, y]^2, {x, y} ∈ funs[[3]]["ElementMesh"]]
(*  1.  *)

% - 1
(*  -4.44089*10^-16  *)

• This is excellent. It seems to give exactly what I want and uses terminology of which I am familiar with. For that reason, I shall mark this as the answer. – Mr S 100 Mar 12 '16 at 0:14

The problem, at least in part, comes from integrating over a region. Since this region is a simple square, you could substitute

NIntegrate[funs[[3]]^2, {x, 0, 1}, {y, 0, 1}, Method -> "LocalAdaptive"]


This evaluates quickly and returns

0.999998

On the other hand,

NIntegrate[funs[[3]]^2, {x, 0, 1}, {y, 0, 1}, Method -> "MultiPeriodic"]


takes longer to evaluate but returns

1.

which be a more accurate value.

• Thanks for your response m_goldberg. This works well! Upvoted! – Mr S 100 Mar 12 '16 at 0:15