3
$\begingroup$

I would like to act with a differential operator $D_x = x \partial_x^2+3\partial_x$ on a function $g(x)$ to compute something like $$ ((D_x)^2 +D_x) g(x) $$ Clearly, in this simple example, this does the trick

dop[t_] := t  D[#, {t, 2}] + 3  D[#, t] &
dop[x][dop[x][g[x]]] + dop[x][g[x]]

However, in my case I have more derivatives and I would like to do things differently. I would like to more generally define a function $f(x) = x^2+x$ and then consider $$ f(D_x)g(x) = ((D_x)^2 +D_x) g(x) $$

How can I define this function $f(D_x)$ in Mathematica?

$\endgroup$
1

1 Answer 1

1
$\begingroup$

We define an operator, that takes a polynomial in x and replaces every x by a derivative operator that acts on the variable x. To prevent that the operator is evaluated too early, we need "Hold":

op[der_] := 
 Evaluate[der /. x^(n_ : 1) :> Hold[D[#, {x, n}]]] & // ReleaseHold

Here is an example:

op[x + 2  x^2 + 3  x^3][x^3]

18 + 12 x + 3 x^2

Of course you may also define the operator that it take an arbitrary variable as argument to act on, but I want to keep it simple.

Addendum

If you want differential operators of the for of a polynomial like e.g. x ∂^2x, we may extend the above.

Define the operator as a function of d with coefficients depending of x:

op[der_] :=  Evaluate[der /. d^(n_ : 1) :> Hold[D[#, {x, n}]]] & // ReleaseHold;

Now if we write e.g.:

op[x d^2][x^2]

2 x

Or

op[a  d^2 + b  x  d][x^2]

2 a + 2 b x^2

Or even:

op[Sin[x]  d][x^2]

2 x Sin[x]
$\endgroup$
3
  • 1
    $\begingroup$ The question needs an operator like $x ∂_x^2$; how would you enter that using your answer? $\endgroup$
    – evanb
    Feb 20 at 14:20
  • $\begingroup$ I'd be also curious to know $\endgroup$
    – bnado
    Feb 22 at 10:42
  • $\begingroup$ Look at the addendum. $\endgroup$ Feb 22 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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