0
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ D[x[t],t] returns x'[t] as you need. Have a look into Help/WolframDocumentation/D. $\endgroup$ Commented Nov 22, 2017 at 11:04
  • $\begingroup$ Take a look at e.g. Using D to find a symbolic derivative $\endgroup$
    – Artes
    Commented Nov 22, 2017 at 11:11
  • $\begingroup$ 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) $\endgroup$
    – Gilgoldman
    Commented Nov 22, 2017 at 11:14
  • $\begingroup$ There's VariationalD to get the variational derivative. Also worth to have a look at EulerEquations, which derives the Euler-Lagrange equations for you. $\endgroup$ Commented Nov 22, 2017 at 13:38

1 Answer 1

0
$\begingroup$

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.

$\endgroup$

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