# Working with functionals [closed]

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

energyFunctional[ψ[1]]


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

energyFunctional[ψ1]
(* 1/2 *)

energyFunctional[ψ2[1]]
(* 1/2 *)

• 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 :) – Nick Aug 20 '15 at 10:53