# Derivative of eigenvalues

I work with 4x4 Hermitian matrices (r). I want to calculate a derivative of a function f[t,r] (ff[t_,r_]=1/2*D[f[t,r],t]), where the function f depends on the absolute value of the eigenvalues of r. Unfortunately, I have failed (for example ff[1,some random r] doesn't give me any numerical value). How should I change my code? Are the eigenvalues I calculate obtained analytically (this should be possible for 4x4 matrices)?

Keep in mind, that r is a 4x4 matrix!!!

sx = {{0, 1}, {1, 0}};
sy = {{0, I}, {-I, 0}};
Mapp1[t_, r_] :=
1/2*(1 + Exp[-t])*r +
1/2*(1 - Exp[-t])*
KroneckerProduct[sx, sy].r.KroneckerProduct[sx, sy];
Eigenvalue1[t_, r_] :=
Eigenvalues[Mapp1[t, r], Cubics -> True, Quartics -> True][[1]];
Eigenvalue2[t_, r_] :=
Eigenvalues[Mapp1[t, r], Cubics -> True, Quartics -> True][[2]];
Eigenvalue3[t_, r_] :=
Eigenvalues[Mapp1[t, r], Cubics -> True, Quartics -> True][[3]];
Eigenvalue4[t_, r_] :=
Eigenvalues[Mapp1[t, r], Cubics -> True, Quartics -> True][[4]];
f[t_, r_] := Sqrt[Eigenvalue1[t, r]^2] +
Sqrt[Eigenvalue2[t, r]^2] + Sqrt[Eigenvalue3[t, r]^2] +
Sqrt[Eigenvalue4[t, r]^2];
ff[t_, r_] = 1/2*D[f[t, r], t]

• Eigenvalues[Mapp1[t, r]] returns unevaluated, because Mapp1[t, r] is not a matrix. Maybe you're missing () around 1/2*(1 + Exp[-t])*r + 1/2*(1 - Exp[-t])? And KroneckerProduct[sx, sy].r.KroneckerProduct[sx, sy] isn't a matrix either. Aug 8, 2019 at 11:45
• If r is a 4x4 matrix, then both Mapp1[t, r] and KroneckerProduct[sx, sy].r.KroneckerProduct[sx, sy] are 4x4 matrices. Aug 8, 2019 at 11:51
• Ah, my mistake, I used a number. Aug 8, 2019 at 11:54
• No, it makes it even worse, as the value of t will be set in before the Mathematica applies the derivative. Aug 8, 2019 at 12:10
• Is this better? ff[t_, r_] := Block[{s}, D[f[s, r], s] /. s -> t]  Aug 8, 2019 at 12:15