This is what I am trying to do:
tmp[func_, arg_, order_] = Derivative[order][func][arg]
Which evaluates to:
$ func^{(order)}[x] $
This seems to be correct, but how can I get the software to evaluate the function at x?
tmp[3x+2, 1, 0]
produces
(2 + 3 x)[1]
and
f[x_] = 3x+2
tmp[f[x], 1, 0]
produces the same thing
However, if I write the function explicitly,
f[x_] = 3x+2
tmp[arg_, order_] = Derivative[order][f][arg]
with
tmp[1, 0]
tmp[1, 1]
I get the expected output of 5
and 3
.
How do I need to define my tmp function so that tmp[3x+2, 1, 0]
evaluates fully?
f[x_] = 2x+1
tmp[func_, arg_, order]
tmp[f, 2, 1]
This seems to work, but I still don't know how to define tmp
in such a way as to allow me to pass in the function or write it within the call.
func
needs to be aFunction
object. If you feed yourtmp
function with just2 + 3 x
, it has no way of knowing what the variable is. Consider: what would happen if you put2 y + 3 x
in it? Do you get3
(the variable isx
)?2
(the variable isy
) ? or0
(the variable is something else)? Here's the link to the documentation onFunction
. $\endgroup$SetDelayed (:=)
. i.e.tmp[func_, arg_, order_] := Derivative[order][func][arg]
andf[x_] := 2x+1
. JustSet (=)
will cause problems. $\endgroup$x
is already defined somewhere else, and it is notClear
ed,2 + 3 x
would be evaluated and your derivative would not work. $\endgroup$