The differential operator in this question is itself indexed by two variables m
and n
. This arises after expressing the Laplace operator in spherical coordinates (see the answer by b.gatessucks, but that answer was incomplete because it dropped the $\phi$ dependence too early) and then assuming that the function on which we operate is proportional to $\exp(im\phi)$.
In the other answers that define a function for this operator, the parameters m
and n
appear as global variables inside the function. That's inconvenient in practice because these indices correspond to physical parameters (the angular momentum components) that are adjustable. So m
and n
need to appear in the list of variables on which the operator depends.
The next thing on which the operator depends is the independent variable $\theta$ with respect to which we want to take derivatives. It would be reasonable to make this work along the lines of D
, which means in particular that it should handle a case like this:
foo[x_] := Sin[θ] Sin[x]
D[foo[θ], θ]
2 Sin[θ] Cos[θ]
This will not work if you define an operator function like this:
myOp = Function[{f, θ}, D[f[θ], θ]];
myOp[foo[θ], θ]
$\sin ^2(\theta )'(\theta )+(2 \sin (\theta )\cos (\theta ))(\theta )$
The problem is that myOp
expects to be passed a function instead of an expression. This is not how D
works. The purpose of the second argument of D[f,x]
is to identify the variable appearing in f
that is to be varied. The above method in myOp
is basically what Nasser used in his answer. It performs a differentiation with respect to the first slot in the first argument assuming it is a function, and then return the result with the variable $\theta$ inserted in that slot. That's not wrong, it's just an interpretation of differentiation that differs from what D
does.
An approach more consistent with D
is this definition:
newOp = Function[{f, θ}, D[f, θ]];
newOp[foo[θ], θ]
2 Cos[θ] Sin[θ]
But in this question, the variable θ
plays a role that is better grouped together with the indices m
and n
, and separated from the function f
on which the operator acts. Now that I identified how I want to think about the variables on which the differential operator depends, the definition I would use is as follows:
Clear[operNM, n, m, var]
operNM[n_, m_, var_] = Function[{f}, D[Sin[var] D[f, var], var]/Sin[var] -
(m^2 f)/Sin[var]^2 + n (n + 1) f
];
This defines operNM[n, m, var]
as an operator to which you then supply an expression that it operates on:
operNM[n,m,θ][foo[θ]]
$\csc (\theta ) \left(4 \sin (\theta ) \cos^2(\theta )-2 \sin ^3(\theta )\right)-m^2+n(n+1) \sin ^2(\theta )$
Having the operator act on expressions instead of expecting its argument to be a function is more practical especially when you deal with functions of several variables. In quantum mechanics, the name of the coordinate in a many-particle wave function is tied to the index of the particle it represents, and function slots are then not a convenient way to keep track of that information. In operNM
you can choose the desired differentiation variable independently of where in the expression it appears.
&
at the end? $\endgroup$&
at the end, and all the#1
's turned Green. What next? $\endgroup$