Suppose that I have the following equations $$\dot{x}(t) = p(t),$$ $$\dot{p}(t) = -V'(x(t)).$$ I am trying to compute the Taylor series of $p(t)$ at $t=0$.

Here are the codes I use:

x'[t_] := p[t]; p'[t_] := -V'[x[t]];

Series[p[t], {t, 0, 2}]

Then I get the result in Mathematica

p[0] - V'[x[0]] t + 1/2 p''[0] t^2 + O[t]^3

But p'' in the result isn't computed.

If I use

D[p[t], {t, 2}]

then I get what I want for $p''$: -p[t]V''[x[t]].

How could I get the Taylor series of any order which compute the higher order derivatives properly?

  • $\begingroup$ What exactly are you expecting? You haven't set p'' to be anything. $\endgroup$
    – Feyre
    Commented Aug 13, 2016 at 10:26
  • 1
    $\begingroup$ Note that the FullForm of p''[t] is Derivative[2][p][t]. For it to work the way you expected, p would have to be defined, not just p'[t], which defines a value only for Derivative[1][p][..]. Or you would have to do some other work around. $\endgroup$
    – Michael E2
    Commented Aug 13, 2016 at 12:51
  • $\begingroup$ @MichaelE2 Thanks for your reminding! $\endgroup$ Commented Aug 13, 2016 at 14:30
  • $\begingroup$ Closely relate, possibly duplicate: How to assign up-values for Derivative? $\endgroup$
    – Jens
    Commented Aug 13, 2016 at 17:08

1 Answer 1


You should define all derivatives of x and p, and not just the first:

Derivative[n_Integer][x][t_] := Derivative[n - 1][p][t]
Derivative[n_Integer][p][t_] := D[-V'[x[u]], {u, n - 1}] /. u -> t


Series[p[t], {t, 0, 3}]

enter image description here

You can choose any order.

  • $\begingroup$ It works! Thanks you very much! $\endgroup$ Commented Aug 13, 2016 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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