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]
  • $\begingroup$ 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. $\endgroup$ – Chris K Aug 8 at 11:45
  • $\begingroup$ If r is a 4x4 matrix, then both Mapp1[t, r] and KroneckerProduct[sx, sy].r.KroneckerProduct[sx, sy] are 4x4 matrices. $\endgroup$ – Agnieszka Aug 8 at 11:51
  • $\begingroup$ Ah, my mistake, I used a number. $\endgroup$ – Chris K Aug 8 at 11:54
  • 2
    $\begingroup$ No, it makes it even worse, as the value of t will be set in before the Mathematica applies the derivative. $\endgroup$ – Agnieszka Aug 8 at 12:10
  • 1
    $\begingroup$ Is this better? ff[t_, r_] := Block[{s}, D[f[s, r], s] /. s -> t] $\endgroup$ – Henrik Schumacher Aug 8 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.