I would like to calculate the second order derivative of a function with respect to a matrix coefficient symbolically. Below is the first order derivative of S with respect to the coefficient of x. For getting the answer what I have done is I have expressed the S as the function of only coefficients.

myD[S , x_[n_, s_]] := D[S[x[n, s]], x[n, s]];

Here S is a function of the big matrix 'x'. But as I said before I need to find the derivative of S with respect to the coefficient of x.

myD[myD[S, x_[n_, s_]], x_[t_, r_]] := 
  D[S[x[n, s]], {x[n, s], 2}];

Above code is what I have written for second derivative and of course it is not correct as what I need is something as below equation.

Is there a best way to define that? $$\sum_{\nu<\mu}\sum_{\beta<\alpha}x_{i\alpha}x_{\beta j}x_{k\mu}x_{\nu\ell}\frac{\partial^{2}S}{\partial x_{\nu\mu}x_{\beta\alpha}}$$ This is how it participate. Definition: $$\frac{\partial^{2}S}{\partial x_{\nu\mu}x_{\beta\alpha}}=\frac{\partial}{\partial x_{\nu\mu}}\left(\frac{\partial S}{\partial x_{\beta\alpha}}\right)$$

If we have, $$K=x_{l\alpha}x_{\beta k}x_{i\nu}x_{\mu j}$$

$$\frac{\partial SK_{\left(\beta\alpha\right),\left(\upsilon\mu\right)}}{dx_{\upsilon\mu}}=S\frac{\partial K_{\left(\beta\alpha\right),\left(\upsilon\mu\right)}}{dx_{\upsilon\mu}}+K\frac{\partial S}{dx_{\upsilon\mu}}$$

$$\frac{\partial^{2}SK_{\left(\alpha\beta\right),\left(\mu\upsilon\right)}}{dx_{\beta\alpha}x_{\upsilon\mu}} =\frac{\partial}{dx_{\beta\alpha}}\left(\frac{\partial SK_{\left(\beta\alpha\right),\left(\upsilon\mu\right)}}{dx_{\upsilon\mu}}\right) =\frac{\partial}{dx_{\beta\alpha}}\left(S\frac{\partial K_{\left(\beta\alpha\right),\left(\upsilon\mu\right)}}{dx_{\upsilon\mu}}+K\frac{\partial S}{dx_{\upsilon\mu}}\right) =\left(S\frac{\partial^{2}K_{\left(\beta\alpha\right),\left(\upsilon\mu\right)}}{dx_{\beta\alpha}x_{\upsilon\mu}}+\frac{\partial K_{\left(\beta\alpha\right),\left(\upsilon\mu\right)}}{dx_{\upsilon\mu}}\frac{\partial S}{dx_{\beta\alpha}}+K\frac{\partial^{2}S}{dx_{\beta\alpha}x_{\upsilon\mu}}+\frac{\partial K_{\left(\beta\alpha\right),\left(\upsilon\mu\right)}}{dx_{\beta\alpha}}\frac{\partial S}{dx_{\upsilon\mu}}\right) $$

provided D is the dimension of the matrix. Also, $$ \frac{\partial x_{lj}}{dx_{\beta\alpha}}=\delta_{j,\alpha}\delta_{l,\beta}-\delta_{j,\beta}\delta_{l,\alpha}$$

EDITED But when I put the rule of differentiation of real antisymmetric matrix as in the above equation by the following code, it is showing error.

myD[x_[k_, l_], 
   x_[v_, g_]] := \[Delta][k, v] \[Delta][l, g] - \[Delta][k, 
     g] \[Delta][l, v];
  • 2
    $\begingroup$ This really depends on how the derivative of S participates in subsequent calculation. Can you show a few examples? $\endgroup$
    – xzczd
    Jul 24, 2020 at 1:29
  • 1
    $\begingroup$ Interesting, I didn't notice this behavior before. It's because stuff inside Format is automatically evaluated (yeah, though := owns the attribute HoldAll). Luckily it's easy to resolve, just add a HoldPattern, see my update. $\endgroup$
    – xzczd
    Jul 24, 2020 at 12:36
  • $\begingroup$ @xzczd No words☺️☺️Amazing $\endgroup$
    – Jasmine
    Jul 24, 2020 at 12:42

1 Answer 1


If it's just for display, then I think the following is enough:

Clear[myD, x]
myD[myD[a_, b__], c__] := myD[a, b, c]

Format[HoldPattern@myD[a_, b__]] := TraditionalForm@HoldForm@D[a, b]

Format[x[a_, b_]] := Subscript[x, a, b]

myD[myD[S, x[ν, μ]], x[α, β]]

enter image description here

To automate the subsequent calculation, just define

myD[a_ + b_, c_] := myD[a, c] + myD[b, c]

and the following two lines that are already in your previous question:

myD[a_ b_, c_] := a myD[b, c] + b myD[a, c]

Format[x[a_, b_]] := Subscript[x, a, b]


myD[myD[S K, x[β, α]], x[ν, μ]]

enter image description here


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.