function construction - How to define custom differential operator using the arguments of the expression?
This is essentially a follow-up to the question/answer here: How to define a differential operator?
Suppose I wish to define an operator DiffOp, e.g.,
DiffOp[t_]:=D[#,t]+4t D[#,{t,2}]&;
but in such a way that the function can read in the argument without having to state it explicitly. Can this be done? If so, how?
In code, what I'd like (using the example above) is a definition that would give
DiffOp[f[x]]
(* f'[x]+4x f''[x] *)
and
DiffOp[x^2+Sin[x]]
(* 10x+Cos[x]-4x Sin[x] *)
Note that I'm not explicitly calling the function as DiffOp[x][...].
Thanks!
Edit: I changed the example expression to be more complicated to test.
Comments
Post a Comment