3
$\begingroup$

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.

$\endgroup$
6
  • 2
    $\begingroup$ Are you sure you did not mean matrix[v_]:= ...? Even better may be to supress any symbolic evaluation with eigenV[v_?NumericQ] :=... and to call ND[eigenV[{x, 1.2, 2.}], x, .2] instead. This works at least with the toy example n = 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$ Commented Sep 7, 2018 at 22:10
  • $\begingroup$ Given the error (unable to find eigenvalues) it seems the problem lies in the calculation of the eigenvalues, not in the taking of the derivative. Can you give an example of the matrix? Maybe it does not have distinct eigenvalues (which might cause the eigensystem to not have eigenvectors). $\endgroup$
    – bill s
    Commented Sep 8, 2018 at 2:16
  • $\begingroup$ It is worth checking that your matrix is exactly numerically Hermitian. Problems can arise if matrices are non-Hermitian through rounding errors. $\endgroup$
    – mikado
    Commented Sep 8, 2018 at 7:55
  • $\begingroup$ @HenrikSchumacher Once parameters are plugged in, the matrix has eigenvectors and eigenvalues in the relevant domain. $\endgroup$
    – induvidyul
    Commented Sep 11, 2018 at 17:06
  • $\begingroup$ @induvidyul Without the actual matrices or the function that produces them, nothing can be said. $\endgroup$ Commented Sep 11, 2018 at 17:08

1 Answer 1

4
$\begingroup$

Okay, the proplem is this: Since eigenV stays unevaluated when called with symbolic arguments, [[2, 1]] operates on the expression eigenV[x, 1, 2, 3, 4, 5, 6, 7, 8][[2, 1]], not on the matrix that you obtain from inserting a numerical value of x. For example

eigenV[x, 1, 2, 3, 4, 5, 6, 7, 8][[x]]

evaluates to x.

So, the following works just fine:

eigenV1[
   x_?NumericQ, y_?NumericQ, z_?NumericQ,
   a_?NumericQ, b_?NumericQ, c_?NumericQ,
   d_?NumericQ, f_?NumericQ, g_?NumericQ
   ] := Transpose[
    SortBy[Transpose[
      Chop[Eigensystem[N[matrix[x, y, z, a, b, c, d, f, g]]]]], 
     First]][[2, 1]];
Needs["NumericalCalculus`"];
ND[eigenV[x, 1, 2, 3, 4, 5, 6, 7, 8], x, 0.2]

{0.132818 + 0.122787 I, -0.00136903, 0., 0.}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.