I have a linear differential operator, for instance, $L\left (\partial _{t} \right )=\partial _{tt} - 3\partial _{t} + 2$. I use it in 2 different ways:
apply the operator to a function: $L\left (\partial _{t} \right )\sin(t)=-\sin(t)-3\cos(t)+2\sin(t)=\sin(t)-3\cos(t)$
find roots of the polynomial $L(p)=0$, in this case $p=1,p=2$
What is the best way to define such operator?
Answer
Define the operator as
op[t_]=(D[#,{t,2}]-3D[#,t]+2#)&
Then you get
op[t][Sin[t]]
(* -3 Cos[t]+Sin[t] *)
and also
op[t][Exp[p t]]/Exp[p t]//Factor
(* (-2+p) (-1+p) *)
where I have used that $\partial_t \exp(p t) = p\exp(p t)$ to "convert" the action of the operator $\partial_t$ into multiplication by $p$, and then I tidy up by dividing out the $\exp(p t)$ afterwards.
Comments
Post a Comment