eig

Syntax

eig(A)

Details

Calculates the eigenvalues and eigenvectors of A.

Note:
  • DolphinDB eig provides the same functionality as numpy.linalg.eigh.
  • numpy.linalg.eig and scipy.linalg.eig are general-purpose eigendecomposition functions. They have a broader scope and are not designed specifically for real symmetric or Hermitian matrices.

Parameters

A is a real symmetric matrix or a Hermitian matrix.

Returns

A dictionary contaning the eigenvalues and eigenvectors of A.

Examples

A = 1 1 2 7 9 3 5 7 0 $ 3:3;
eig(A);
/* output
vectors->
#0        #1       #2
--------- -------- ---------
0.839752  0.169451 -0.515852
-0.301349 0.935753 -0.18318
0.45167   0.309277 0.836864

values->[1.716868,10.17262,-1.889488]
*/

For the eigenvalue of 1.716868, the corresponding eigenvector is:

eig(A).vectors[0];
// output: [0.839752,-0.301349,0.45167]

Use numpy.linalg.eigh to calculate the eigenvalues and eigenvectors of the same matrix. The returned eigenvalues may appear in a different order, and the signs of the eigenvectors may be reversed, but the results are mathematically equivalent.

import numpy as np

A = np.array([[1., 7., 5.],
              [1., 9., 7.],
              [2., 3., 0.]])

w, v = np.linalg.eigh(A)

print("values:")
print(w)

print("vectors:")
print(v)


""" Output:
values:
[-1.88948817  1.71686814 10.17262003]
vectors:
[[-0.51585193  0.83975187 -0.16945081]
 [-0.18318039 -0.30134864 -0.93575314]
 [ 0.83686422  0.45167    -0.30927736]]
"""