5

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.

user21
  • 39,710
  • 8
  • 110
  • 167
Mr S 100
  • 711
  • 6
  • 11
  • 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: http://mathematica.stackexchange.com/questions/41212/nintegrateslwcon-problem/41216#41216 – leibs Mar 11 '16 at 22:23
  • @MrS100 Is an error of around 10^-6 acceptable? If so, you can use the result. – Michael E2 Mar 11 '16 at 22:43
  • 3
    Try to integrate over the ElementMesh from the InterpolatingFunction and see if that helps. – user21 Mar 11 '16 at 23:23
  • Good Idea - this certainly doesn't show an error message anymore – Mr S 100 Mar 12 '16 at 00:11

2 Answers2

4

*[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  *)
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • 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 00:14
3

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.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257