[Scientific / technical calculation by Python] Numerical solution of eigenvalue problem of matrix by power method, numerical linear algebra

Introduction

In science and engineering, we often solve eigenvalue problems in quantum mechanics and oscillator systems.

Power method is a standard eigenvalue problem.

A\mathbf{u} = \lambda \mathbf{u}

It is one of the algorithms to find the maximum eigenvalue (dominant eigenvalue) of the absolute value of. ** ** When you open the introductory book around that area, you will often see it first.

** It is a very educational content for learning the elementary numerical solution of the eigenvalue problem. In this article, we will consider this method. ** **

This method is very straightforward.

Calculation procedures and points are

  1. Set an appropriate initial estimated eigenvector $ u_0 $.
  2. Multiply $ u_0 $ by A ($ AAAAAA ... \ mathbf {u_0} = A ^ k \ mathbf {u_0} \ (k-> ∞) $.
  3. Then, the direction vector converges to the constant vector $ \ mathbf {u'} $.
  4. ** In many cases, the $ \ mathbf {u'} $ is the eigenvector corresponding to the largest absolute value eigenvalue! ** **
  5. u'If is an eigenvector, the corresponding eigenvalue\lambdaIs\mathbf{u^T}A\mathbf{u}/(|u|^2)Can be given.

So, the main thing to do is to multiply the ** A to check the convergence of the direction vector. ** ** Then, the origin of the name "power method" is because of the method of evaluating the power of the coefficient matrix A, as can be seen in 2 above.

If you are concerned about the mathematical basis of 4 above, please refer to the addendum of this article.

Also, the power method is a method to find the eigenvalue of the maximum absolute value of A. ** With some ingenuity, it is possible to find the eigenvalue with the smallest absolute value, the eigenvalue closest to the given complex number $ z $, the second eigenvalue, and so on. ** I'm planning to post a hey article.


Contents

Solve a simple eigenvalue problem that applies the power method, However, make sure that you get the eigenvalue with the maximum absolute value and the corresponding eigenvector.

As $ A $ of $ A \ mathbf {u} = \ lambda \ mathbf {u} $

A=
\left[
\begin{matrix}
1 & 2 \\
3 & 4 
\end{matrix}
\right]

Think about.

The exact solution for the maximum eigenvalue of the absolute value is $ \ frac {5+ \ sqrt {33}} {2} = 5.372281323 ... $.


code

As a convergence test condition Absolute value of change in $ \ lambda $ in repeating steps $ k $ and $ k + 1 $ \frac{|\lambda_{k+1}-\lambda_k|}{| \lambda_k|} \lt \epsilon=0.0001Repeat the calculation until.

"""
Matrix eigenvalue problem:Power method:
"""

import numpy as np

A=np.array([[1,2],[3,4]])

x0 = np.array([1,0]); x1 = np.array([0,1])
u = 1.0*x0+2.0*x1 #The initial eigenvector. Appropriate.

rel_eps = 0.0001 #Eigenvalue convergence conditions
#Krylov column generation

rel_delta_u=100.0
while rel_delta_u >= rel_eps :  #Main loop
    uu = u/np.linalg.norm(u) #Normalization(Set the norm to 1)
    print("u=",uu)
    
    u = np.dot(A,uu.T)

    eigen_value=np.dot(uu,u)/(np.dot(uu,uu.T))

    print("eigen_value=",eigen_value)
    
    delta_u_vec = uu-u/np.linalg.norm(u)
    abs_delta_u_value= np.linalg.norm(delta_u_vec)
    rel_delta_u=abs_delta_u_value/np.abs(eigen_value) #Relative change in eigenvalues for repeated steps
    print("rel_delta_u_vec = ",rel_delta_u)


result



u= [ 0.41612395  0.9093079 ]
eigen_value= 5.37244655582
rel_delta_u_vec =  3.29180183204e-05

You can see that it matches very well with the exact solution 5.372281323 ...


References

The following books have been helpful in writing this article. [1] is a simple description and easy to understand. [2] is a summary of how to solve the eigenvalue problem using numpy and scipy.

[1] Gilbert Strang, ["World Standard MIT Textbook Strang: Linear Algebra Introduction"](https://www.amazon.co.jp/%E4%B8%96%E7%95%8C%E6%A8%99 % E6% BA% 96MIT% E6% 95% 99% E7% A7% 91% E6% 9B% B8-% E3% 82% B9% E3% 83% 88% E3% 83% A9% E3% 83% B3% E3% 82% B0-% E7% B7% 9A% E5% BD% A2% E4% BB% A3% E6% 95% B0% E3% 82% A4% E3% 83% B3% E3% 83% 88% E3 % 83% AD% E3% 83% 80% E3% 82% AF% E3% 82% B7% E3% 83% A7% E3% 83% B3-% E3% 82% AE% E3% 83% AB% E3% 83% 90% E3% 83% BC% E3% 83% 88 / dp / 4764904055 / ref = pd_lpo_sbs_14_t_0? _ Encoding = UTF8 & psc = 1 & refRID = 9817PCQXDR5497M5GPS2), Modern Science, 2015.

[2] [[Science / technical calculation by Python] Solving (generalized) eigenvalue problem using numpy / scipy, using library] (http://qiita.com/sci_Haru/items/034c6f74d415c1c10d0b)


Addendum

The power method is the standard eigenvalue problem

A\mathbf{u} = \lambda \mathbf{u}

In

Starting from the initial vector $ u_0 $

u_i = Au_{i-1}, (i=1,2,...)

This is a method to find the eigenvalue / eigenvector with the maximum absolute value. (This $ u_0, Au_0, A ^ 2u_0, A ^ 3u_0 $, ... is [Kurilov column](https://ja.wikipedia.org/wiki/%E3%82%AF%E3%83%AA% It is called E3% 83% AD% E3% 83% 95% E9% 83% A8% E5% 88% 86% E7% A9% BA% E9% 96% 93))

Now, the eigenvalue equation $Au_i = \lambda_i u_i$

In ** eigenvalues have no degeneracy **, that is, $\lambda_i \neq \lambda_j \ (i \neq j)$

Suppose. Also, regarding the order of the magnitude of the eigenvalues

|\lambda_1| > |\lambda_2|>|\lambda_3|...

Suppose.|\lambda_1|Is the eigenvalue with the maximum absolute value, and I want to find it by the power method.

Now consider a suitable vector $ u_0 $. Suppose the coefficient $ c_i $ is fixed so that $ u_0 $ can be expanded as follows.

u_0 = c_1 \mathbf{u_1} + c_2 \mathbf{u_2}+c3 \mathbf{u_3}+...

When $ A ^ k $, which should be $ A $, is applied to this,

A^k u_0 = c_1 A^k \mathbf{u_1} + c_2 A^k \mathbf{u_2} + c_3 A^k \mathbf{u_3}+...
= c_1 \lambda_1^k \mathbf{u_1} + c_2 \lambda_2^k \mathbf{u_2} + c_3 \lambda_3^k\mathbf{u_3} +...
=\lambda_1^k (c_1 \mathbf{u_1} + c_2 \lambda_2^k/\lambda_1^k \mathbf{u_2} + c_3 \lambda_3^k/\lambda_1^k\mathbf{u_3}) +...

It will be.

|\lambda_1|Is the largest eigenvalue, so for a large power number k\lambda_2^k/\lambda_1^kOr\lambda_3^k/\lambda_1^k ...Should converge to zerois. In other words

(k-> ∞ )A^k u_0 => \lambda_1^k (c_1 \mathbf{u_1} )

You can expect it to be.

By repeatedly applying $ A $ to the ** initial trial vector $ u_0 $ in this way, a vector parallel to the eigenvector corresponding to the eigenvalue with the maximum absolute value is obtained. ** **

The eigenvector always has a constant multiple (arbitrary complex number multiple) indefiniteness (it means that the eigenvalue does not change even if both sides of the eigenexpression are multiplied by a complex number), so the one that suits the purpose is selected. In most cases, the one with a norm of 1 is chosen.

The eigenvalue $ \ lambda $ with the maximum absolute value is from the eigenvalue equation for a sufficiently large $ k $.

\lambda = \frac{u_k^T A u_k}{u_k^T u_k} =\frac{u_k^T u_{k+1}}{u_k^T u_k}

Can be calculated as. This is the Rayleigh quotient (https://ja.wikipedia.org/wiki/%E3%83%AC%E3%82%A4%E3%83%AA%E3%83%BC%E5%95 It is called% 86).

As described above, it is possible to calculate the eigenvalue with the maximum absolute value of the eigenvalue problem and the corresponding eigenvector.

Caution

  1. When using the power method, the condition that the eigenvalue of $ A $ is not duplicated must be satisfied. ** If the eigenvalues are degenerate or close, the solution will not converge or will require too many iterative steps to converge **. 2.Real matrix is complex eigenvaluezIf, its conjugate complex numberz*Is also an eigenvalue. That time|z|=|z*|Therefore, the eigenvalues will be the same. If they have the maximum absolute value, the situation in 1 above will occur and the solution will not converge.

Recommended Posts

[Scientific / technical calculation by Python] Numerical solution of eigenvalue problem of matrix by power method, numerical linear algebra
[Scientific / technical calculation by Python] Numerical solution of one-dimensional harmonic oscillator problem by velocity Verlet method
[Scientific / technical calculation by Python] List of matrices that appear in Hinpan in numerical linear algebra
[Scientific / technical calculation by Python] Sum calculation, numerical calculation
[Scientific / technical calculation by Python] Solving the boundary value problem of ordinary differential equations in matrix format, numerical calculation
[Scientific / technical calculation by Python] Numerical solution of two-dimensional Laplace-Poisson equation by Jacobi method for electrostatic potential, elliptic partial differential equation, boundary value problem
[Scientific / technical calculation by Python] Solving simultaneous linear equations, numerical calculation, numpy
[Scientific / technical calculation by Python] 2D random walk (drunk walk problem), numerical calculation
[Science / technical calculation by Python] Numerical solution of first-order ordinary differential equations, initial value problem, numerical calculation
[Scientific / technical calculation by Python] Numerical solution of one-dimensional and two-dimensional wave equations by FTCS method (explicit method), hyperbolic partial differential equations
[Scientific / technical calculation by Python] Inverse matrix calculation, numpy
[Scientific / technical calculation by Python] Lagrange interpolation, numerical calculation
[Scientific / technical calculation by Python] Calculation of matrix product by @ operator, python3.5 or later, numpy
[Scientific / technical calculation by Python] Solving (generalized) eigenvalue problem using numpy / scipy, using library
[Scientific / technical calculation by Python] Solving second-order ordinary differential equations by Numerov method, numerical calculation
[Scientific / technical calculation by Python] Numerical calculation to find the value of derivative (differential)
[Scientific / technical calculation by Python] Analytical solution to find the solution of equation sympy
[Scientific / technical calculation by Python] Numerical solution of one-dimensional unsteady heat conduction equation by Crank-Nicholson method (implicit method) and FTCS method (positive solution method), parabolic partial differential equation
[Scientific / technical calculation by Python] Basic operation of arrays, numpy
[Scientific / technical calculation by Python] Monte Carlo integration, numerical calculation, numpy
[Scientific / technical calculation by Python] Numerical integration, trapezoidal / Simpson law, numerical calculation, scipy
[Scientific / technical calculation by Python] Monte Carlo simulation of thermodynamics of 2D Ising spin system by Metropolis method
[Scientific / technical calculation by Python] Fitting by nonlinear function, equation of state, scipy
[Scientific / technical calculation by Python] Histogram, visualization, matplotlib
[Scientific / technical calculation by Python] Drawing animation of parabolic motion with locus, matplotlib
[Scientific / technical calculation by Python] Drawing of 3D curved surface, surface, wireframe, visualization, matplotlib
[Scientific / technical calculation by Python] Solving one-dimensional Newton equation by the 4th-order Runge-Kutta method
Numerical calculation of compressible fluid by finite volume method
[Scientific / technical calculation by Python] Logarithmic graph, visualization, matplotlib
Calculation of homography matrix by least squares method (DLT method)
[Scientific / technical calculation by Python] Polar graph, visualization, matplotlib
[Scientific / technical calculation by Python] Plot, visualization, matplotlib of 2D data read from file
[Scientific / technical calculation by Python] Drawing, visualization, matplotlib of 2D (color) contour lines, etc.
[Python] Numerical calculation of two-dimensional thermal diffusion equation by ADI method (alternate direction implicit method)
[Scientific / technical calculation by Python] Solving the Schrodinger equation in the steady state in the 3D isotropic harmonic oscillator potential by the matrix method, boundary value problem, quantum mechanics
[Scientific / technical calculation by Python] 3rd order spline interpolation, scipy
[Numerical calculation method, python] Solving ordinary differential equations by Eular method
[Scientific / technical calculation by Python] List of usage of (special) functions used in physics by using scipy
[Scientific and technical calculation by Python] Drawing of fractal figures [Sierpinski triangle, Bernsley fern, fractal tree]
Scientific / technical calculation by Python] Drawing and visualization of 3D isosurface and its cross section using mayavi
[Scientific / technical calculation by Python] Vector field visualization example, electrostatic field, matplotlib
[Scientific / technical calculation by Python] 1D-3D discrete fast Fourier transform, scipy
Story of power approximation by Python
[Science / technical calculation by Python] Comparison of convergence speeds of SOR method, Gauss-Seidel method, and Jacobi method for Laplace equation, partial differential equation, boundary value problem
[Scientific / technical calculation by Python] Derivation of analytical solutions for quadratic and cubic equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Solving ordinary differential equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Solving one-dimensional Schrodinger equation in stationary state by shooting method (1), well-type potential, quantum mechanics
[Scientific / technical calculation by Python] Plot, visualize, matplotlib 2D data with error bars
[Scientific / technical calculation by Python] Solving one-dimensional Schrodinger equation in stationary state by shooting method (2), harmonic oscillator potential, quantum mechanics
Calculation of technical indicators by TA-Lib and pandas
Identity matrix and inverse matrix: Linear algebra in Python <4>
Matrix Calculations and Linear Equations: Linear Algebra in Python <3>