You can use my function MatrixD from the question det simplification:
MatrixD[expr_, x__] := With[
{old = OptionValue[SystemOptions[], "DifferentiationOptions"->"ExcludedFunctions"]},
Internal`WithLocalSettings[
SetSystemOptions["DifferentiationOptions"->"ExcludedFunctions"->Join[old, {Det, Inverse, Tr}]];
Unprotect[D];
(* handle list derivatives *)
D[h:((Det|Tr|Inverse)[m_]), {z_, n_Integer}] := Nest[D[#, Replace[z, _List :> {z}]]&, h, n];
D[h:((Det|Tr|Inverse)[m_]), {z_List}] := D[h, #]& /@ z;
D[h:((Det|Tr|Inverse)[m_]), z_, y___] := D[D[h, z], y];
(* define derivatives for Det, Tr, and Inverse *)
D[Det[m_], z:Except[_List]] := Det[m] Tr[Inverse[m] . D[m,z]];
D[Tr[m_], z:Except[_List]] := Tr[D[m,z]];
D[Inverse[m_], z:Except[_List]] := -Inverse[m] . D[m, z] . Inverse[m],
D[expr, x],
SetSystemOptions["DifferentiationOptions"->"ExcludedFunctions"->old];
Clear[D];
Protect[D]
]
]
For your example:
g[x_] := g0 + x g2 + x^2 g4 + x^3 g6 + x^3 hd Log[x];
Then:
coeffs = Table[
MatrixD[Sqrt[Det[g[x]]] /. Log[x]->u, {x, n}]/n! /. {x->0, u->Log[x]},
{n, 0, 3}
];
Print @* TeXForm /@ coeffs;
$\sqrt{\left| \operatorname{g0}\right| }$
$\frac{1}{2} \sqrt{\left| \operatorname{g0}\right| } \operatorname{Tr}\left[\operatorname{g0}^{-1}.\operatorname{g2}\right]$
$\frac{1}{2} \left(\frac{1}{2} \sqrt{\left| \operatorname{g0}\right| } \operatorname{Tr}\left[\left(-\operatorname{g0}^{-1}.\operatorname{g2}.\operatorname{g0}^{-1}\right).\operatorname{g2}+\operatorname{g0}^{-1}.(2 \operatorname{g4})\right]+\frac{1}{4} \sqrt{\left| \operatorname{g0}\right| } \operatorname{Tr}\left[\operatorname{g0}^{-1}.\operatorname{g2}\right]^2\right)$
$\frac{1}{6} \left(\frac{1}{2} \sqrt{\left| \operatorname{g0}\right| } \operatorname{Tr}\left[2 \left(-\operatorname{g0}^{-1}.\operatorname{g2}.\operatorname{g0}^{-1}\right).(2 \operatorname{g4})+\left(-\left(-\operatorname{g0}^{-1}.\operatorname{g2}.\operatorname{g0}^{-1}\right).\operatorname{g2}.\operatorname{g0}^{-1}-\operatorname{g0}^{-1}.\operatorname{g2}.\left(-\operatorname{g0}^{-1}.\operatorname{g2}.\operatorname{g0}^{-1}\right)-\operatorname{g0}^{-1}.(2 \operatorname{g4}).\operatorname{g0}^{-1}\right).\operatorname{g2}+\operatorname{g0}^{-1}.(6 \operatorname{g6}+6 \operatorname{hd} \log (x))\right]+\frac{3}{4} \sqrt{\left| \operatorname{g0}\right| } \operatorname{Tr}\left[\operatorname{g0}^{-1}.\operatorname{g2}\right] \operatorname{Tr}\left[\left(-\operatorname{g0}^{-1}.\operatorname{g2}.\operatorname{g0}^{-1}\right).\operatorname{g2}+\operatorname{g0}^{-1}.(2 \operatorname{g4})\right]+\frac{1}{8} \sqrt{\left| \operatorname{g0}\right| } \operatorname{Tr}\left[\operatorname{g0}^{-1}.\operatorname{g2}\right]^3\right)$
Let's evaluate the first few terms of the series using an explicit set of matrices:
SeedRandom[2];
rules = Thread[{g0, g2, g4, g6, hd} -> RandomReal[1,{5,3,3}]]
{g0 -> {{0.72224, 0.109449, 0.470703}, {0.535582, 0.583178,
0.293942}, {0.165154, 0.601258, 0.754218}},
g2 -> {{0.771123, 0.778574, 0.0236104}, {0.922757, 0.992454,
0.350409}, {0.0450047, 0.501359, 0.633756}},
g4 -> {{0.642208, 0.389875, 0.664971}, {0.843882, 0.56904,
0.398212}, {0.238652, 0.673513, 0.419507}},
g6 -> {{0.587398, 0.00833523, 0.942441}, {0.771263, 0.147503,
0.964774}, {0.898747, 0.332963, 0.204548}},
hd -> {{0.839035, 0.250388, 0.238638}, {0.616616, 0.879303,
0.404504}, {0.402517, 0.516192, 0.292009}}}
And the comparison:
N @ CoefficientList[Series[Sqrt[Det[g[x]]] /. rules, {x, 0, 3}], x]
coeffs /. rules //Expand
{0.507317, 0.663253, 0.436586, 0.0826776 + 0.572028 Log[x]}
{0.507317, 0.663253, 0.436586, 0.0826776 + 0.572028 Log[x]}
MatrixPower
to evaluateg
, then find its determinant usingDet
then take the square root of the result usingSqrt
then useSeries
on the result. $\endgroup$