# Taylor series of functions with defined derivatives?

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?

• What exactly are you expecting? You haven't set p'' to be anything. – Feyre Aug 13 '16 at 10:26
• 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. – Michael E2 Aug 13 '16 at 12:51
• @MichaelE2 Thanks for your reminding! – Chichipingguo Aug 13 '16 at 14:30
• Closely relate, possibly duplicate: How to assign up-values for Derivative? – Jens Aug 13 '16 at 17:08

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


Then

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


You can choose any order.

• It works! Thanks you very much! – Chichipingguo Aug 13 '16 at 14:31