3

Is there a way to differentiate with respect to an expression, instead of a single variable in Maxima CAS? Here is a toy example, which should give $\frac{\partial}{\partial x^2}x^2=1$:

diff(x^2,x^2);

with an error in wxMaxima 20.06.6

diff: second argument must be a variable; found x^2

For clarity, I meant first derivative with respect to an expression of $x$, not a second derivative with respect to $x$ itself. Note that the latter gives $\frac{\partial^2}{\partial x^2}x^2=2\ne 1$ and can be easily computed as diff(x^2,x,2)

enter image description here

  • @OlegMelnikov: Do you mean diff(x^2,x,2); ? Of course, the result is $2$? You can try it online at http://maxima.cesga.es/index.php?c=tqbml5ttggw1vr2lpas4o&n=1 – Moo Jan 01 '22 at 02:53
  • @Moo, good question. I meant the first derivative. See additional clarification. – Oleg Melnikov Jan 01 '22 at 03:24

1 Answers1

5

Just apply the chain rule in the CAS

$$\frac{df(x)}{dg(x)}=\frac{\frac{df(x)}{dx}}{\frac{dg(x)}{dx}}$$

Just define $g(x)$ and apply.

  • Good observation. I'll mark it as correct. Here is the code for your example: diff(x^4,x)/diff(x^2,x); and diff(x^2,x)/diff(x^2,x); – Oleg Melnikov Jan 01 '22 at 03:28