The linear algebra that you will definitely learn at a science university is summarized in an easy-to-understand and logical manner. By the way, I implemented it in Python. Occasionally, it may be implemented in Julia. .. .. ・ Learn by running with Python! New Mathematics Textbook-Basic Knowledge Required for Machine Learning / Deep Learning- ・ World Standard MIT Textbook Strang Linear Algebra Introduction Understand linear algebra based on and implement it in python.
・ Jupyter Notebook ・ Language: Python3, Julia 1.4.0
Eigenvalues and eigenvectors are used in principal component analysis to summarize data with artificial intelligence.
Consider the square matrix A. For this matrix A
A\vec{x}=λ\vec{x}
When meeting
λ is the eigenvalue of the matrix A\\
\vec{x}The eigenvectors of the matrix A\\
That is.
Multiply the above equation by the identity matrix E, which does not affect the vector.
A\vec{x}=λE\vec{x}
Transfer and organize the right side
(A-λE)\vec{x} = \vec{0}
This represents a vector with all 0 *** elements. On the other hand, even if the inverse matrix is considered, it is zero. It is a vector. This equation is called *** eigen equation ***.
(A-λE)\vec{x} = \vec{0}
along,
A=\begin{pmatrix}3 & 1\\2 & 4\end{pmatrix}
As a concrete example. Then
det(A-λE)\vec{x} = 0\\
⇔
det(\begin{pmatrix}3 & 1\\2 & 4\end{pmatrix}-λ\begin{pmatrix}1 & 0\\0 & 1\end{pmatrix})\vec{x} = 0\\
⇔
det\begin{pmatrix}3-λ & 1\\2 & 4-λ\end{pmatrix} = 0\\
⇔(λ-2)(λ-5)= 0\\
This makes the *** eigenvalue 2 or 5 ***. Because the eigenvector also changes depending on the eigenvalue. Think about each of the cases 2 and 5.
\vec{x} = \begin{pmatrix}p\\q\end{pmatrix}
If you calculate with λ = 2,
det(A-λE)\vec{x} = 0\\
\begin{align}
det(A-λE)\vec{x}&=
det(A-2E)\begin{pmatrix}p\\q\end{pmatrix} \\
&=\begin{pmatrix}1 & 1\\2 & 2\end{pmatrix}\begin{pmatrix}p\\q\end{pmatrix}\\
&=\begin{pmatrix}p+q\\2p+2q\end{pmatrix} \\
&= \vec{0}
\end{align}
From this, it can be said that p + q = 0, so if you put an arbitrary real number t, the x vector will be
\vec{x}=\begin{pmatrix}t\\-t\end{pmatrix}
And the eigenvectors are obtained.
When λ = 5,
\vec{x}=\begin{pmatrix}t\\2t\end{pmatrix}
Will be.
python
7pythoneigenvaluevector
import numpy as np
A = np.array([[3, 1],[2, 4]])
ev = np.linalg.eig(A)
print(ev[0])
print(ev[1])
[2. 5.]
[[-0.70710678 -0.4472136 ]
[ 0.70710678 -0.89442719]]
Here we are using the linag.eig function
. This is because the eigenvalues are in English and are called *** eigenvalue ***.
Let's make a principle program. This time, the eigenvalues are calculated.
7pythoneigenvaluevector2
import numpy as np
import sympy
#A = [[a, b],
# [c, d]]
a = int(input())
b = int(input())
c = int(input())
d = int(input())
#=>3
#=>1
#=>2
#=>4
x = sympy.Symbol('x')
eigenequa = x**2 - (a + d)*x + (a * d) - (b * c)```
print(eigenequa)
factorization = sympy.factor(eigenequa)
print(factorization)
solve = sympy.solve(eigenequa)
print(solve)
=>x**2 - 7*x + 10
=>[2, 5]
julia is so easy that I'll put it on.
7juliaigenvaluevector
using LinearAlgebra
F = eigen([3 1; 2 4;])
=>Eigen{Float64,Float64,Array{Float64,2},Array{Float64,1}}
=>values:
=>2-element Array{Float64,1}:
=> 2.0
=> 5.0
=>vectors:
=>2×2 Array{Float64,2}:
=> -0.707107 -0.447214
=> 0.707107 -0.894427
Only 2 lines! Wow...
That's all for today
Recommended Posts