I am trying to work with functionals in Mathematica, this means that I want to define a function of a function. I defined my function of a function as:

energyFunctional[ψ_] := 
Integrate[1/2 (D[ψ[x], x])^2 + 1/2*x^2*(ψ[x])^2, {x, -∞,∞}];

This works really good when I just want to fill in a simple function defined as for example:

ψ=(1/π)^(1/4) Exp[-(#^2/2)]&

But as soon as I try to add a parameter to vary my function it all fails, given that I define:

ψ[b_] := (b/π)^(1/4) Exp[-((b*#^2)/2)] &

and try to do


I get no results at all.

  • 2
    $\begingroup$ Typo? the function names are not identical, I do get result energyfunctionaal[ψ[1]]-> 1/2. $\endgroup$ – rhermans Aug 20 '15 at 10:16
  • $\begingroup$ FWIW; it's atypical to pass around anonymous functions. Just pass around expressions instead (i.e. omit the & at the end). $\endgroup$ – C. E. Aug 20 '15 at 10:21
  • 2
    $\begingroup$ Two typos, in fact: functionaal and Functional (lowercase and doubled "a"). $\endgroup$ – Patrick Stevens Aug 20 '15 at 10:29
  • $\begingroup$ @rhermans Sorry acknowledged the typo in the comment to halirutan's answer. But my question is answered! $\endgroup$ – Nick Aug 20 '15 at 11:06
  • $\begingroup$ @rhermans no problem at all ;-). I should have posted the aknowlegement also as a comment to my question. $\endgroup$ – Nick Aug 20 '15 at 11:10

You should correct the typo in your code. I'm not even sure how this can happen, when you copied the example from your notebook.

Additionally, you shouldn't use $\psi$ for both, a function and a variable. Once this is fixed:

energyFunctional[ψ_] := 
   1/2 (D[ψ[x], x])^2 + 
    1/2*x^2*(ψ[x])^2, {x, -∞, ∞}];

ψ1 = (1/π)^(1/4) Exp[-(#^2/2)] &
ψ2[b_] := (b/π)^(1/4) Exp[-((b*#^2)/2)] &

you get

(* 1/2 *)

(* 1/2 *)
  • $\begingroup$ The typo was because of the fact that I was simultaneously copying and translating, my bad. And this was indeed the solution that I tried, and it still didn't work. But closing and reopening the kernel cured it :) $\endgroup$ – Nick Aug 20 '15 at 10:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.