Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I defined a one-dimensional momentum operator $\hat{p}=-i\hbar\frac{\partial}{\partial{x}}$ in Mathematica

p = -I * h * D[#, x]&

and I want to get the kinetic energy operator $\hat{T}=\hat{p}^2/2m=-\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}$ from it, so

T = p^2/(2m)

but it gives the wrong result

What can I do about it? Do I have to derive the operators by hand?

share|improve this question
up vote 3 down vote accepted

You can't just squre an operator since no multiplication of functions (operators) are defined in Mathematica. You have to write something like

T = (p@p@#)/(2 m) &


T = p[p[#]]/(2 m) &
share|improve this answer

Here is a more generalized method for what you want to do:

Let's define our momentum operator as you did above:

P := -I * h * D[#, x]&

Then we can define the nth power operator in a more general way as:

T[n_] := Nest[P, #, n] &

So for example the Kinetic energy operator (which is P^2 / (2 m)) will be:

T[2] / (2 m)

And we can use it on some function f as follows

(1/ (2 m))T[2]@(E^(I k x))

Which gives:

Mathematica graphics

as expected.

Now if we want P^3 we just use T[3] etc.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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