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} = 
    {-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.

  • $\begingroup$ 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 $\endgroup$ – leibs Mar 11 '16 at 21:04
  • $\begingroup$ 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. $\endgroup$ – Mr S 100 Mar 11 '16 at 21:16
  • $\begingroup$ 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." $\endgroup$ – Mr S 100 Mar 11 '16 at 21:16
  • $\begingroup$ 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/… $\endgroup$ – leibs Mar 11 '16 at 22:23
  • 3
    $\begingroup$ Try to integrate over the ElementMesh from the InterpolatingFunction and see if that helps. $\endgroup$ – 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  *)
| improve this answer | |
  • $\begingroup$ 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. $\endgroup$ – 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


On the other hand,

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

takes longer to evaluate but returns


which be a more accurate value.

| improve this answer | |
  • $\begingroup$ Thanks for your response m_goldberg. This works well! Upvoted! $\endgroup$ – Mr S 100 Mar 12 '16 at 0:15

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.