# How to find the derivative of one matrix with respect to another?

I have an expression from a continuum model,which looks somewhat like this excluding a few constants.

Here epsilon is the 3x3 strain tensor and sigma is 3x3 stress tensor. I wish to compute the derivative of sigma with respect to epsilon. As you may see, it is an implicit relation and it is posing some challenges which I am unable to work around.

I have tried using the ImplicitD function, which works well for computing the derivative of implicit scalar functions. For instance, if y = sin(y)+x , then the derivative of y with respect to x is 1/(1-cos(y)). This is correctly computed by the ImplicitD function in Mathematica.

ImplicitD[y, Sin[y] + x - y == 0, y, x]


returns

1/(1 - Cos[y])


as expected. However, when I tried using ImplicitD for the same for the matrix expression mentioned above,

ImplicitD[sig, -1/(1 - Tr[eps])*Tr[sig]*IdentityMatrix[3] + 1/(1 - Tr[eps])*sig - eps == 0, eps]


I get the following error:

• You have probably posted this question on the wrong site. This site is about Wolfram Mathematica Software, while your question is about mathematics, and should be posted on Mathematics StackExchange. Jan 16, 2023 at 14:57
• No, I know to compute the derivative by hand. I want to know how to do the same operation, specifically in Mathematica. Jan 16, 2023 at 15:03
• Then please include all relevant information: (1) how to compute the derivative by hand, and (2) Mathematica code for your tensors or whatever you have tried so far. Jan 16, 2023 at 15:04
• The community expects the following from you: ✅: A clear description of an on-topic problem or goal. ❌: A minimal working Wolfram Language code example, formatted, easy to copy&paste, in Raw InputForm,not images. ❌. An example of what you expect as output. ❌. Some proof of minimal Mathematica knowledge. ❌. Minimum due diligence: Share how you have searched the site and documentation, your attempts and reasons to believe an answer exists. Jan 16, 2023 at 15:17
• If you are unable to do all the things that @rhermans thoroughly explained, at least give a PROPER mathematical description of the problem.
– bmf
Jan 16, 2023 at 15:27

It is not clear what the derivative relative to a matrix means. I assume that you mean the derivative relative to each matrix element. This can be done with "D".

For simplicity to get you started, here is a 2D example: To get the derivative of matrix ms relative to matrix me, we must write the matrix elements of ms as functions of the elements of me:

n = 2;
me = Array[e, {n, n}];
vars = Flatten[me]
ms = Array[(StringJoin["s", ToString[#1], ToString[#2]] @@
vars) &, {n, n}]


Now, for your problem, we first solve the implicit equation for the elements of matrix sigma, then we replace the elements of sigma by the solutions and do the derivative:

sig = Array[
Symbol@StringJoin["s", ToString[#1], ToString[#2]] &, {n, n}]
sol = Solve[-1/(1 - Tr[eps])*Tr[sig]*IdentityMatrix[2] +
1/(1 - Tr[eps])*sig - eps == 0, Flatten[sig]]


sig1 = sig /. sol[[1]]


D[sig1, {{Flatten[eps]}}]


• Thank you for the precise answer sir! This is exactly what I was looking for. Jan 16, 2023 at 19:53