Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Artes, rcollyer, RunnyKine, Oleksandr R., Sjoerd C. de Vries May 19 '14 at 21:36

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.

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. – murray May 19 '14 at 19:58
@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. – Alex R. May 19 '14 at 20:03
@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? – Alex R. May 19 '14 at 20:05
@Artes: Derivative seems to work! Thanks! – Alex R. May 19 '14 at 20:09
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. – murray May 20 '14 at 0:42

1 Answer 1

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


share|improve this answer

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