I'm trying to calculate the derivative of an eigenvector that I obtain by
matrix[x_?NumericQ, y_?NumericQ, ...]:={...};];
eigenV[x_?NumericQ, y_?NumericQ, ...]:= Transpose@SortBy[Transpose[Chop[Eigensystem[N[matrix[x,y,...]]]]], First];
Needs["NumericalCalculus`"];
ND[eigenV[x, ...][[2, 1]], x, 0.2]
I get
Eigensystem::eivec0: Unable to find all eigenvectors.
{0., 0., 0., 0.}
However, I can evaluate the eigenvalues and eigenvectors at this (and any other) point numerically with no problem.
Is there another way to force Eigensystem[]
to evaluate numerically when it is wrapped in ND[]
?
The derivative obviously works on a minimal 2x2 example, presumably because symbolic evaluation is trivial. MWE:
matrix[x_?NumericQ, y_?NumericQ, z_?NumericQ, a_?NumericQ, b_?NumericQ, c_?NumericQ]:={{-c + b x + a z, a (x - I y)}, {a (x + I y), -c + b x - a z}};
It doesn't work when it's 4x4, which technically should also be symbolically tractable, but whose matrix elements are more complicated.
matrix[x_?NumericQ, y_?NumericQ, z_?NumericQ, a_?NumericQ, b_?NumericQ, c_?NumericQ, d_?NumericQ, f_?NumericQ, g_?NumericQ ]:=
{{-a + b (1 + d) - (-1 + d) Sqrt[-c^2 (-6 + 2 Cos[y] Cos[z] + 2 Cos[x] (Cos[y] + Cos[z]) + 8 Cos[z/2] (Cos[y/2] Sin[x/2]^2 + Cos[x/2] Sin[y/2]^2) + 8 Cos[x/2] Cos[y/2] Sin[z/2]^2)], f + E^(-(1/2) I (x + y)) g + E^(-(1/2) I (x + z)) g + E^(-(1/2) I (y+z)) g, 0, 0},
{f + (E^(1/2 I (x + y)) + E^(1/2 I (x + z)) + E^(1/2 I (y + z))) g, -a-b+b d - 2 (1 + d) Sqrt[c^2 ((Cos[y/2] - Cos[z/2])^2 Sin[x/2]^2 + (Cos[x/2] - Cos[z/2])^2 Sin[y/2]^2 + (Cos[x/2] - Cos[y/2])^2 Sin[z/2]^2)], 0, 0},
{0, 0, -a + b + b d - 2 (1 + d) Sqrt[c^2 ((Cos[y/2] - Cos[z/2])^2 Sin[x/2]^2 + (Cos[x/2] - Cos[z/2])^2 Sin[y/2]^2 + (Cos[x/2] - Cos[y/2])^2 Sin[z/2]^2)],
f + E^(-(1/2) I (x + y)) g + E^(-(1/2) I (x + z)) g + E^(-(1/2) I (y + z)) g},
{0, 0, f + (E^(1/2 I (x + y)) + E^(1/2 I (x + z)) + E^(1/2 I (y + z))) g, -a - (-1 + d) (-b +Sqrt[-c^2 (-6 + 2 Cos[y] Cos[z] + 2 Cos[x] (Cos[y] + Cos[z]) +
8 Cos[z/2] (Cos[y/2] Sin[x/2]^2 + Cos[x/2] Sin[y/2]^2) +
8 Cos[x/2] Cos[y/2] Sin[z/2]^2)])}};
My eventual desired size is 8x8.
matrix[v_]:= ...
? Even better may be to supress any symbolic evaluation witheigenV[v_?NumericQ] :=...
and to callND[eigenV[{x, 1.2, 2.}], x, .2]
instead. This works at least with the toy examplen = 8; A = RandomReal[{-1, 1}, {n, n}]; A = A\[Transpose].A; B = RandomReal[{-1, 1}, {n, n}]; B = B\[Transpose] + B; matrix[v_] := A + v B; eigenV[v_?NumericQ] := Transpose@SortBy[Transpose[Chop[Eigensystem[N[matrix[v]]]]], First];
. $\endgroup$