# Need help with computing symbolic derivatives [duplicate]

Imagine you are trying to get an equation of motion (in my case, the Lagrangian of a coupled drives CE108 system).

In such a case, you need to symbolically define certain derivatives as themselves, not as their value (i.e. D[x] = x' instead of D[x] = 1).

Is there any way within Mathematica to derive completely symbolically?

Complicated Example:

f = x' + mx + 7y
SymbolicDerivative[f,x] = x'' + mx'


Edit regarding duplication: This question tries to find a way to partially derive a function symbolically continuously - meaning, derive x to x' and then x'' and then x''' and so forth rather than trying to derive a function and plug values in

• D[x[t],t] returns x'[t] as you need. Have a look into Help/WolframDocumentation/D. Commented Nov 22, 2017 at 11:04
• Take a look at e.g. Using D to find a symbolic derivative Commented Nov 22, 2017 at 11:11
• Both are helpful, thanks Artes and Alexei! However, the question is about finding a derivative or partial derivative of an entire function with respect to, say, x in a way that returns, for example, x' from x, not about expressing x' (which was a very helpful tip Alexei, thanks again) Commented Nov 22, 2017 at 11:14
• There's VariationalD to get the variational derivative. Also worth to have a look at EulerEquations, which derives the Euler-Lagrange equations for you. Commented Nov 22, 2017 at 13:38

This can be done by using total derivatives (Dt) and defining additional constraints:

f=Dt[x]+m x+7 y
Dt[f] /. {Dt[m] -> 0, Dt[y] -> 0}
(* output -> m Dt[x] + Dt[Dt[x]] *)


In short, take the total derivative of f, and then hold every variable but x constant.

An automatic function for doing this process is provided below:

symD[f_, x_] := Module[{y, r},
r = Dt[f];
y = #[[1 ;; -2]] & /@ Position[r, Dt];
y = Part[r, Sequence @@ #] & /@ y;
y = DeleteDuplicates[Pick[y, Length[#] == 1 & /@ Dimensions /@ y]];
y = Select[y, Not[#[[1]] === x] &];
y = # -> 0 & /@ y;
r /. y]


It takes the total derivative and then assumes that all variables aside from the one entered as x have a total derivative equal to 0.

Note however that in most situations it's far more practical to define x as a function of another variable and take the derivative with respect to that.