Guest User

Untitled

a guest
Dec 16th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. det(M) = det( ( A11 + B11, A12 + B12), (A21 + B21, A22 + B22) )
  2.  
  3. = det( ( A11 + 0, A12 + 0), (A21 + B21, A22 + B22) )
  4. + det( ( 0 + B11, 0 + B12), (A21 + B21, A22 + B22) )
  5.  
  6. = det( ( A11 + 0, A12 + 0), (A21 + 0, A22 + 0) )
  7. + det( ( A11 + 0, A12 + 0), (0 + B21, 0 + B22) )
  8.  
  9. + det( ( 0 + B11, 0 + B12), (A21 + 0, A22 + 0) )
  10. + det( ( 0 + B11, 0 + B12), (0 + B21, 0 + B22) )
  11.  
  12. = det( ( A11, A12), (A21, A22) )
  13. + det( ( A11, A12), (B21, B22) )
  14. + det( ( B11, B12), (A21, A22) )
  15. + det( ( B11, B12), (B21, B22) )
  16.  
  17. det(M) =
  18. = det( ( A11, A12), (A21, A22) )
  19. + x det( ( A11, A12), (C21, C22) )
  20. + x det( ( C11, C12), (A21, A22) )
  21. + x^2 det( ( C11, C12), (C21, C22) )
  22.  
  23. MatrixD[expr_, x__] := With[
  24. {old = OptionValue[SystemOptions[], "DifferentiationOptions"->"ExcludedFunctions"]},
  25.  
  26. Internal`WithLocalSettings[
  27. SetSystemOptions["DifferentiationOptions"->"ExcludedFunctions"->Join[old, {Det, Inverse, Tr}]];
  28.  
  29. Unprotect[D];
  30. (* handle list derivatives *)
  31. D[h:((Det|Tr|Inverse)[m_]), {z_, n_Integer}] := Nest[D[#, Replace[z, _List :> {z}]]&, h, n];
  32. D[h:((Det|Tr|Inverse)[m_]), {z_List}] := D[h, #]& /@ z;
  33. D[h:((Det|Tr|Inverse)[m_]), z_, y___] := D[D[h, z], y];
  34.  
  35. (* define derivatives for Det, Tr, and Inverse *)
  36. D[Det[m_], z:Except[_List]] := Det[m] Tr[Inverse[m] . D[m,z]];
  37. D[Tr[m_], z:Except[_List]] := Tr[D[m,z]];
  38. D[Inverse[m_], z:Except[_List]] := -Inverse[m] . D[m, z] . Inverse[m],
  39.  
  40. D[expr, x],
  41.  
  42. SetSystemOptions["DifferentiationOptions"->"ExcludedFunctions"->old];
  43. Clear[D];
  44. Protect[D]
  45. ]
  46. ]
  47.  
  48. g[x_] := g0 + x g2 + x^2 g4 + x^3 g6 + x^3 hd Log[x];
  49.  
  50. coeffs = Table[
  51. MatrixD[Sqrt[Det[g[x]]] /. Log[x]->u, {x, n}]/n! /. {x->0, u->Log[x]},
  52. {n, 0, 3}
  53. ];
  54. Print @* TeXForm /@ coeffs;
  55.  
  56. SeedRandom[2];
  57. rules = Thread[{g0, g2, g4, g6, hd} -> RandomReal[1,{5,3,3}]]
  58.  
  59. N @ CoefficientList[Series[Sqrt[Det[g[x]]] /. rules, {x, 0, 3}], x]
  60.  
  61. coeffs /. rules //Expand
Add Comment
Please, Sign In to add comment