I am trying to verify my hand solution for a HW problem using Mathematica.

I noticed that I get correct eigenvalues from Mathematica using DEigenvalues but when looking at the eigenfunctions, using same operator, using NDEigensystem and when I ask for first eigenfunction, it gives correct one, when I ask for the first two, now they get flipped upside down !

They are correct, but needed to multiply them all by minus sign to get same result as hand solution.

Why does this happen?

Here is the problem to find its eigenvalues and eigefunctions.

\begin{align*} y''(x) + \lambda y(x) &= 0 \\ y(0)-y'(0) &=0\\ y(\pi)-y'(\pi) &=0 \end{align*}

Eigenvalues are $\lambda=-1$ and $\lambda=n^2$ for $n=1,2,3,\dots$. Mathematica agrees:


Mathematica graphics

So, assuming I did everyhing OK so far, lets now look at eigfunction associated with $\lambda=-1$. Mathematica finds this to be $e^x$ which is correct, but only when asking for the first one: (notice, there is normalization term, which can be ignored. Just looking at the shape).


Mathematica graphics

Now notice what happens when asking for the first two


Mathematica graphics

It flipped! The correct one is $e^x$ and not $-e^x$, as Mathematica verifies:

ode=y''[x]+ lam y[x]==0;

Mathematica graphics

Question is: Why do eigenfunctions from NDEigensystem are flipped when asking for more than one? They all get flipped, not just the first one.

Mathematica 11.3, windows 7.

  • $\begingroup$ Well, I'm not quite familiar with eigenvalue problem, but if I've understood definition of eigenfunction correctly, any function that fits the form C[1] Exp[x] is the corresponding eigenfunction for $\lambda=-1$ in your case, am I missing something? $\endgroup$ – xzczd Apr 12 '18 at 4:48
  • $\begingroup$ @xzczd my question is why when asking for first eigenfunction, it shows as $\exp(x)$, but when asking for the first two eigenfunctions, it shows the first now as $-\exp(x)$. Why did the sign change? The book says also it should be $\exp(x)$ and not $-\exp(x)$. May be in theory both are valid (have to ask the teacher about this), but why did Mathematica give one sign one time and another sign the next time? $\endgroup$ – Nasser Apr 12 '18 at 4:51
  • 2
    $\begingroup$ This is a peculiarity of the algorithm. It not wrong. So it can flip signs as it likes. Note that NIntegrate[# Conjugate[#], {x, 0, π}] & /@ Through[eigFunctions[x]] gives 1 for every eigenfunction. $\endgroup$ – user21 Apr 12 '18 at 5:32
  • $\begingroup$ This happens ubiquitously in eigenvalue problems. It can depend on the number of eigenfunctions you require and also parameters in the equation. Quite annoying if you wish to make an animation of eigenfunctions (many sudden changes due to flips). It's nothing wrong albeit hard to control. $\endgroup$ – xiaohuamao Apr 13 '18 at 0:46
  • $\begingroup$ @xiaohuamiao yes, I understand. This is like having an indefinite integral that return a constant of integration. One time you call it, it returns 10 as constant of the integration. Next time, it returns -10 or 99 or 20.34, all are correct. But all what I am saying, it is nice to return the same thing, that is all. I understand it is hard to control when there are many algorithms involved. I am just talking from user point of view. Not an internal/implementation point of view. $\endgroup$ – Nasser Apr 13 '18 at 7:15

First of all, as mentioned in the comment above, $-e^x$ is not wrong, and any function that fits the form $c_1 e^x$ ($c_1$ is non-zero, of course) is the corresponding eigenfunction for $\lambda=-1$ in your case, according to the definition of eigenfunction. Then why doesn't NDEigensystem always give the same form? I don't have a complete answer, the only thing I know is, the sign is inherited from Eigensystem together with "Arnoldi" method:

internal = Trace[NDEigensystem[op, y, {x, 0, Pi}, 2], HoldPattern@Eigensystem[__]] // 

Mathematica graphics

internal[[1]] // ReleaseHold // Transpose // Last
(* {-0.999999, {-0.0164892, -0.0192938, -0.0225755, -0.0264153, …… *)

internal[[1, 1, 2]] = -1;
internal[[1]] // ReleaseHold
(* {{-0.999999}, {{0.0164892, 0.0192938, 0.0225755, …… *)

internal[[1]] /. (Method -> a_) :> Sequence[] // ReleaseHold
(* {{-0.999999}, {{-0.0164892, -0.0192938, -0.0225755, -0.0264153, …… *)
  • $\begingroup$ Ok, thanks. My main complaint was it that Mathematica gives different result depending if user asked for one or two. This is just confusing from user point of view, even though it is theoretically correct. I think it should stick to one sign and not change it depending on how many the user wanted. But it looks like this is how it is designed to work. Ok. Just confuses one. $\endgroup$ – Nasser Apr 12 '18 at 5:39

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.