I'm trying to evaluate interpolating function returned by NDEigensystem at a point but Mathematica won't evaluate it.

{vals, funs} = NDEigensystem[-Laplacian[u[x], {x}], u[x], {x, 0, \[Pi]}, 4];
 f = funs[[3]] (*3rd eigenfunction*)
Plot[f[x], {x, 0, Pi}] (*this plot returns blank plot*)
Plot[f, {x, 0, Pi}] (*this plot works fine*)

As you can see, f[2] is not evaluated. Any help with the problem with the plot and function evaluation would be appreciated.

enter image description here


Change u[x] to u

{vals, funs} =NDEigensystem[-Laplacian[u[x], {x}], u , {x, 0, \[Pi]}, 4] 



does what you are looking for.

To plot all the eigenfunctions try Plot[Through[funs[x]],{x,0,Pi}]

enter image description here

  • $\begingroup$ Thank you so much, this fixed my problem. $\endgroup$ – Omar Nagib Jul 15 '19 at 13:33
  • $\begingroup$ You're welcome! $\endgroup$ – Ulrich Neumann Jul 15 '19 at 13:33
  • $\begingroup$ On a related note, how can I define new functions using my interpolating function f (or manipulate interpolating functions in general)? For example in my above code, if I define ff=f+2 or ff=2*f, I'm not able to evaluate this function (e.g., ff[2] does not evaluate). Or how can I define new function ff= Sin[x]*f for example? $\endgroup$ – Omar Nagib Jul 15 '19 at 13:50
  • 1
    $\begingroup$ Try ff = FunctionInterpolation[2 funs[[3]][x], {x, 0, Pi}] or fff = Function[{x}, funs[[3]][x] + 2] $\endgroup$ – Ulrich Neumann Jul 15 '19 at 13:53
  • 1
    $\begingroup$ There are no errors in both variants( of my comment). Perhaps the second variant is preferable. $\endgroup$ – Ulrich Neumann Jul 15 '19 at 14:09

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.