# Different eigenfunctions are generated if I change the number of eigenfunctions I want to have

I was experimenting with solving differential equations using eigenfunction expansions. I was troubled by the fact that my solution was very different from the solution produced by NDSolve, so I examined my code and noticed the following issue.

I have the following code in Mathematica:

Clear["Global*"]
a[x_] := 2
b[x_] := x + 1
c[x_] := 0
L = 2 Pi;
ODE = Exp[Integrate[b[x]/a[x], x]] y''[x] +
Exp[Integrate[b[x]/a[x], x]] b[x]/a[x]*y'[x] +
Exp[Integrate[b[x]/a[x], x]] c[x]/a[x]*y[x] ==
Exp[Integrate[b[x]/a[x], x]] f[x]/a[x];
n0 = 30;
{eigV, eigF} =
NDEigensystem[{ODE[[1]], DirichletCondition[y[x] == 0, True]},
y, {x, 0, L}, n0];
eigF[[2]][5]
Plot[eigF[[2]][x], {x, 0, L}]


As I understand it (I might be wrong), the commands:

eigF[[2]][5]
Plot[eigF[[2]][x], {x, 0, L}]


should give the same answer whether n0=3 or n0=30. But this does not happen. Why?

They are the same.

Remember, sign on eigenvector do not make difference. It is arbitrary.

n0 = 30;
{eigV, eigF} =
NDEigensystem[{ODE[[1]], DirichletCondition[y[x] == 0, True]},
y, {x, 0, L}, n0];
eigF[[2]][5]
Plot[eigF[[2]][x], {x, 0, L}]


n0=3;
{eigV,eigF}=NDEigensystem[{ODE[[1]],DirichletCondition[y[x]==0,True]},y,{x,0,L},n0]
-eigF[[2]][5]
Plot[-eigF[[2]][x],{x,0,L}]
`

• You are right. For me (Mathematica 13.3), the one eigenfunction was simply the opposite of the other. I didn't notice, in my desperation to find where I went wrong. Thank you, anyway! Commented Jun 19 at 7:40