4
$\begingroup$

This question already has an answer here:

I want to define an operator $(\partial_{t}+1)^{2}=\partial_{t}\partial_{t}+2\partial_{t}+1$. Then, I want it to act on $t$. My code looks like this:

op[t_] := (D[#, {t, 1}] + 1 #)^2 &
op[t][t]

Instead of giving $2+t$, its result is $(1+t)^{2}.$ To verify if $2+t$ is really the answer, I write the right-hand side of the operator in Mathematica. My code looks like this:

op[t_] := (D[#, {t, 2}] + 2*D[#, {t, 1}] + 1 #) &
op[t][t]

And, it gives $2+t$. I want to write the exponent explicitly because I plan to extend it to $5$ (instead of $2$), and act it on another function. Can someone help me on this? Thank you.

$\endgroup$

marked as duplicate by Carl Woll, MarcoB, Henrik Schumacher, José Antonio Díaz Navas, m_goldberg Apr 3 '18 at 12:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ I apologize. It should be $(\partial_{t}+1)^{2}t=2+t$. $\endgroup$ – RaymartJay Mar 27 '18 at 6:56
  • $\begingroup$ $(\partial_{t}+1)^{2}t=(\partial_{t}^{2}+2\partial_{t}+1)t= (\partial_{t}^{2}t+2\partial_{t}t+t)=(2+t)$ $\endgroup$ – RaymartJay Mar 27 '18 at 7:03
  • $\begingroup$ @CarlWoll, I actuallly referred to How to define a differential operator?, but, still, my operator does not give the correct answer. $\endgroup$ – RaymartJay Mar 27 '18 at 7:07
  • $\begingroup$ What is meant by "act it on another function" and "act on" (in this context)? $\endgroup$ – Peter Mortensen Mar 27 '18 at 13:00
  • 1
    $\begingroup$ @PeterMortensen, what I meant by "act on" is the usual operation done by a differential operator on a function. And "act it on another function" means using another function instead of the function t. I hope this clarifies your question. $\endgroup$ – RaymartJay Mar 27 '18 at 14:16
3
$\begingroup$

You want to use composition, not powers:

op := (D[#, {t, 1}] + #) &

op[t]

Out[86]= 1 + t

op[op[t]]

Out[87]= 2 + t

Composition[op, op]@t

Out[97]= 2 + t

Apply[Composition, Table[op, 5]]@(t^5)

Out[99]= 120 + 600 t + 600 t^2 + 200 t^3 + 25 t^4 + t^5

Expand[(x + 1)^5]

Out[101]= 1 + 5 x + 10 x^2 + 10 x^3 + 5 x^4 + x^5

$\endgroup$
  • 1
    $\begingroup$ Off topcic note: to play with it one needs to copy it and manually drop/delete In[85] and friends. Consider not pasting them and insert output as e.g. commented code or quoted block (> ) $\endgroup$ – Kuba Mar 27 '18 at 7:05
  • $\begingroup$ Thank you. I think this is better. $\endgroup$ – RaymartJay Mar 27 '18 at 7:21
7
$\begingroup$

(From my answer to the linked question)

Install the DifferentialOperator paclet with:

PacletInstall["https://github.com/carlwoll/DifferentialOperator/releases/download/0.1/DifferentialOperator-0.0.1.paclet"]

and load with:

<<DifferentialOperator`

The paclet defines an input auto replacement for a special partial character, which you must use instead of the normal \[Partial] character. Specifically, you must enter pd and not EscpdEsc. Then, you can define a differential operator and apply it to a function as follows:

enter image description here

$\endgroup$
  • $\begingroup$ Thank you. But, I don' understand why I get $0[t]$ instead of $2+t$. $\endgroup$ – RaymartJay Mar 27 '18 at 7:24
  • $\begingroup$ @RaymartJay Assuming you loaded my paclet, then you should use pd, not esc pd esc to enter the partial symbol. $\endgroup$ – Carl Woll Mar 27 '18 at 7:28
  • $\begingroup$ @CarlWoll, I am using your paclet for a project of mine and I am wondering if you put a built in function to make a change of variable in the differential operators ? $\endgroup$ – Ezareth Jul 17 '18 at 10:27

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