# Problems with the eigenvalues calculated using NDEigenvalue

I'm trying to solve a Sturm-Liouville problem like

$$\qquad -\psi''(z)+(\frac{1}{z}+2\,z)\psi'(z)=\lambda\,\psi(z)$$

using NDEigensystem in order to learn how to use this tool. The spectrum should be {4, 8, 12, 16, 20, ...}.

I tried this code for the equation above:

{mass,states} =
NDEigensystem[
{-psi''[z]+(1/z + 2 z)psi[z], DirichletCondition[psi[z] == 0, True]}, psi[z], {z, 0, 20}, 8,
Method ->
{"SpatialDiscretization"->{"FiniteElement",
"MeshOptions"->{"MaxCellMeasure"->0.0001}}}]


where Eqn is just the differential (Liouville) operator that I defined above. I also impose Dirichlet conditions for $$\psi(z)$$ at $$z\to 0$$.

But I getting some problems with this code.

First, the eigenvalues change (a lot) when I change the interval. For example, with [0, 10] I get {4, 8, 12, 16, 20.001, 27.3062-2.30156 I}. When I change the interval to [0, 20], I get {4., 8., 12., 15.8473, 17.0221-1.78342I, 17.0221+1.78342I, 17.6018-4.75387I, 17.6018+4.75387I}.

Second, (as you can see above), the eigenvalues appear with non-zero imaginary part. This problem has real eigenvalues, so I don't understand what it is happening.

I have read the information about NDEigenvalues, but I still do not understand why I'm getting these problems. So if anyone could give me some advice I would be thankful.

• Can you show your code for the psi[z] ? And what output do you get when you run the code you provided so far? – CA Trevillian May 2 at 19:07
• Yeah, sure! Let me re-write the question! – Mike May 2 at 20:50
• sweet! Let me know when you post the function definitions and I’ll take a look, there could be something in your syntax, and I am just generically a curious scientist :) but also I can’t help you properly without it – CA Trevillian May 3 at 1:47
• Mmm, when you say function definitions, are you thinking on how I define the boundary conditions or something related? If that's so, then I used Dirichlet conditions at the origin and it is supposed that the function is real-valued. – Mike May 3 at 21:14
• I believe you are trying to solve a problem on the half line. But instead, you ask Mathematica to solve a Dirichlet problem on a finite interval. Note that it seems to me that your code imposes a Dirichlet condition at both ends. As you change the interval, you change the problem and get different results, as one should expect (the whole line eigenfunctions have no reason to all vanish at x=10 or x=20...) – Francois Vigneron May 8 at 9:13