1
$\begingroup$

I have a function $\phi(t)$ and I want to define a function $\phi D(t,r):=\phi^{(r)}(t)$, in other words evaluate the $r$'th derivative of $\phi$ at $t$. The naive code that I have is:

phiD[t_, r_] = D[phi[t], {t, r}]

which doesn't work, because Mathematica doesn't know to evaluate the $r$ part first and then the $t$ part. What's the easiest way to implement this?

$\endgroup$
5
  • $\begingroup$ I don't understand what the problem is that you face. If you dart, say, with phi[t_] := Sin[t]^5 Cos[t]^3, then phiD[t_, r_] = D[phi[t], {t, r}] returns essentially D[Cos[t]^3*Sin[t]^5, {t, r}]. And then phiD[t, 6] will give the correct 6th derivative as a function of t; you may then replace t with any particular numeric value. $\endgroup$
    – murray
    May 19 '14 at 19:58
  • $\begingroup$ @murray: If you put in 'phiD[1,6]' you will get an error that '1' is not a valid variable. I am using Mathematica 9. $\endgroup$
    – Alex R.
    May 19 '14 at 20:03
  • $\begingroup$ @Artes: In the answers to the linked question, I don't see $s$ being substituted for a number anywhere. For example in the accepted answer, there's still the free variable $s$ that was differentiated in. Perhaps I'm misunderstanding something? $\endgroup$
    – Alex R.
    May 19 '14 at 20:05
  • $\begingroup$ @Artes: Derivative seems to work! Thanks! $\endgroup$
    – Alex R.
    May 19 '14 at 20:09
  • $\begingroup$ Yes, that's exactly as to be expected: if you put in a constant for the variable t in phiD[t_, r_] = D[phi[t], {t, r}], you're asking to take the tth derivative of a constant rather than of a function depending on a variable. And you're solution provided as an Answer certainly avoids that. I just wasn't clear what the original problem was. $\endgroup$
    – murray
    May 20 '14 at 0:42
1
$\begingroup$

In the comments, Artes suggested the Derivative function. This works:

phiD[t_,r_]=Derivative[r][phi][t]

$\endgroup$

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