関数eigen3 マニュアル

(The documentation of function eigen3)

Last Update: 2025/8/7


◆機能・用途(Purpose)

3×3行列の固有値・固有ベクトルを計算する。
Compute the eigenvalues and eigenvectors of a 3×3 matrix.


◆形式(Format)

#include <matrix/eigen.h>
inline struct eigen_info eigen3(struct matrix original_matrix)


◆引数(Arguments)

original_matrix 固有値・固有ベクトルを求めたい3×3行列。
A 3×3 matrix for which the eigenvalues and eigenvectors are to be solved.


◆戻り値(Return value)

引数original_matrixで与えた行列の固有値・固有ベクトル。
The eigenvalues and eigenvectors of the matrix given by argument original_matrix.


◆使用例(Example)

struct matrix M=get_matrix_memory(3,3);
M.main[0][0]=1.2;
M.main[0][1]=3.4;
M.main[0][2]=5.6;
M.main[1][0]=7.8;
M.main[1][1]=9.0;
M.main[1][2]=-1.2;
M.main[2][0]=-3.4;
M.main[2][1]=-5.6;
M.main[2][2]=-7.8;
struct eigen_info principal_axis=eigen3(M);


◆計算式(Formula)


1. 固有値(Eigenvalues)

行列 \[\begin{equation} {\bf A}= \begin{pmatrix} a & b & c \\ d & e & f \\ g & h & i \end{pmatrix} \label{eq.matrixDef} \end{equation}\] に対する固有値\(\lambda\)は \[\begin{eqnarray} |\lambda {\bf I}-{\bf A}| &=& \begin{vmatrix} \lambda-a & -b & -c \\ -d & \lambda-e & -f \\ -g & -h & \lambda-i \end{vmatrix} \nonumber \\ &=& (\lambda-a)(\lambda-e)(\lambda-i)-bfg-cdh \nonumber \\ & & -fh(\lambda-a)-cg(\lambda-e)-bd(\lambda-i) \nonumber \\ &=& \lambda^3 - (a+e+i)\lambda^2 \nonumber \\ & & + (ae+ei+ia-bd-cg-fh)\lambda \nonumber \\ & & -(aei+bfg+cdh-afh-ceg-bdi) \nonumber \\ &=& 0 \label{eq.eigenEquation} \end{eqnarray}\] を解くことで求められる。 ここで\({\bf I}\)は\(3\times 3\)の単位行列である。 この関数ではequation.h内の関数eqsol3を用いて (\ref{eq.eigenEquation})を解くことで固有値\(\lambda\)を求めている。
The eigenvalues \(\lambda\) of a matrix given by eq. (\ref{eq.matrixDef}) can be obtained by solving eq. (\ref{eq.eigenEquation}), where \({\bf I}\) is a \(3\times 3\) unit matrix. This function solves eq. (\ref{eq.eigenEquation}) for the eigenvalues \(\lambda\) using function ``eqsol3'' in ``equation.h''.


2. 固有ベクトル(Eigenvectors)

固有値\(\lambda\)に対する固有ベクトルを\((\nu_1,\nu_2,\nu_3)^T\)とすると、 固有ベクトルの定義より \[\begin{equation} \begin{pmatrix} a & b & c \\ d & e & f \\ g & h & i \end{pmatrix} \begin{pmatrix} \nu_1 \\ \nu_2 \\ \nu_3 \end{pmatrix} = \lambda \begin{pmatrix} \nu_1 \\ \nu_2 \\ \nu_3 \end{pmatrix} \label{eq.eigenvector_relation} \end{equation}\] であるので \[\begin{equation} (\lambda-a)\nu_1-b\nu_2-c\nu_3=0 \label{eq.eigenvector_relation.1} \end{equation}\] \[\begin{equation} -d\nu_1+(\lambda-e)\nu_2-f\nu_3=0 \label{eq.eigenvector_relation.2} \end{equation}\] \[\begin{equation} -g\nu_1-h\nu_2+(\lambda-i)\nu_3=0 \label{eq.eigenvector_relation.3} \end{equation}\] が成り立つ。\(\lambda\)が固有値であるので、 この3本の方程式のうち独立なものは2つである。 そこで(\ref{eq.eigenvector_relation.1})(\ref{eq.eigenvector_relation.2}) を使用することとし、これらを\(\nu_3\)が与えられた時に\(\nu_1\), \(\nu_2\)を求める 連立方程式と見なすと、その解はクラメルの公式から \[\begin{equation} \nu_1=\frac{ \begin{vmatrix} c & -b \\ f & \lambda-e \end{vmatrix} }{ \begin{vmatrix} \lambda-a & -b \\ -d & \lambda-e \end{vmatrix} }\nu_3 \label{eq.nu1_nu3_relation} \end{equation}\] \[\begin{equation} \nu_2=\frac{ \begin{vmatrix} \lambda-a & c \\ -d & f \end{vmatrix} }{ \begin{vmatrix} \lambda-a & -b \\ -d & \lambda-e \end{vmatrix} }\nu_3 \label{eq.nu2_nu3_relation} \end{equation}\] となる。\(\nu_1\), \(\nu_2\), and \(\nu_3\)は この関係を満たす限りにおいて自由に選べるので、特に \[\begin{equation} \nu_3 = \begin{vmatrix} \lambda-a & -b \\ -d & \lambda-e \end{vmatrix} \label{eq.nu3} \end{equation}\] とおいて1つの固有ベクトル \[\begin{equation} \nu_1= \begin{vmatrix} c & -b \\ f & \lambda-e \end{vmatrix} \label{eq.nu1} \end{equation}\] \[\begin{equation} \nu_2= \begin{vmatrix} \lambda-a & c \\ -d & f \end{vmatrix} \label{eq.nu2} \end{equation}\] を得る。但し、このようにして求めた固有ベクトル\((\nu_1,\nu_2,\nu_3)^T\)は 長さが1とは限らないので、 一旦上の式によって固有ベクトルを求めた後で長さ1になるように規格化する。
Let \((\nu_1,\nu_2,\nu_3)^T\) be the eigenvector corresponding to an eigenvalue \(\lambda\). The definition of an eigenvector gives eq. (\ref{eq.eigenvector_relation}) which can be rewritten as eqs (\ref{eq.eigenvector_relation.1})-(\ref{eq.eigenvector_relation.3}). Only two of these three equations are independent because \(\lambda\) is an eigenvector. We use eqs (\ref{eq.eigenvector_relation.1}) and (\ref{eq.eigenvector_relation.2}), regarding them as a simultaneous equation for \(\nu_1\) and \(\nu_2\) given \(\nu_3\). The solutions of this simultaneous equation are eqs (\ref{eq.nu1_nu3_relation}) and (\ref{eq.nu2_nu3_relation}). The values of \(\nu_1\), \(\nu_2\), and \(\nu_3\) can be taken arbitrarily as long as they satisfy these relations. One of the simplest choice would be (\ref{eq.nu3}), in which case we obtain eqs (\ref{eq.nu1}) and (\ref{eq.nu2}) for \(\nu_1\) and \(\nu_2\), respectively. After obtaining one of the eigenvectors in this way, we normalize it so that the length is 1.

解の導出に用いた(\ref{eq.nu1_nu3_relation})(\ref{eq.nu2_nu3_relation})式に 分数が登場するので分母が0(すなわち\(\nu_3=0\))の場合に困りそうだが、 (\ref{eq.nu3})-(\ref{eq.nu2})の解自体は\(\nu_3=0\)の場合であっても 固有ベクトルの要件 (\ref{eq.eigenvector_relation.1})-(\ref{eq.eigenvector_relation.3}) を満たす。実際、(\ref{eq.nu3})-(\ref{eq.nu2})の解を (\ref{eq.eigenvector_relation.1})-(\ref{eq.eigenvector_relation.3}) の左辺に代入すると \[\begin{eqnarray} (\lambda-a)\nu_1-b\nu_2-c\nu_3 &=& (\lambda-a) \begin{vmatrix} c & -b \\ f & \lambda-e \end{vmatrix} -b \begin{vmatrix} \lambda-a & c \\ -d & f \end{vmatrix} -c \begin{vmatrix} \lambda-a & -b \\ -d & \lambda-e \end{vmatrix} \nonumber \\ &=& (\lambda-a)[c(\lambda-e)+bf] \nonumber \\ & & -b[(\lambda-a)f+cd] \nonumber \\ & & -c[(\lambda-a)(\lambda-e)-bd] \nonumber \\ &=& c(\lambda-a)(\lambda-e)+bf(\lambda-a) \nonumber \\ & & -bf(\lambda-a)-bcd \nonumber \\ & & -c(\lambda-a)(\lambda-e)+bcd \nonumber \\ &=& 0 \label{eq.check_eigenvector_1} \end{eqnarray}\] \[\begin{eqnarray} -d\nu_1+(\lambda-e)\nu_2-f\nu_3 &=& -d \begin{vmatrix} c & -b \\ f & \lambda-e \end{vmatrix} +(\lambda-e) \begin{vmatrix} \lambda-a & c \\ -d & f \end{vmatrix} -f \begin{vmatrix} \lambda-a & -b \\ -d & \lambda-e \end{vmatrix} \nonumber \\ &=& -d[c(\lambda-e)+bf] \nonumber \\ & & +(\lambda-e)[(\lambda-a)f+cd] \nonumber \\ & & -f[(\lambda-a)(\lambda-e)-bd] \nonumber \\ &=& -cd(\lambda-e)-bdf \nonumber \\ & & +f(\lambda-a)(\lambda-e)+cd(\lambda-e) \nonumber \\ & & -f(\lambda-a)(\lambda-e)+bdf \nonumber \\ &=& 0 \label{eq.check_eigenvector_2} \end{eqnarray}\] \[\begin{eqnarray} -g\nu_1-h\nu_2+(\lambda-i)\nu_3 &=& -g \begin{vmatrix} c & -b \\ f & \lambda-e \end{vmatrix} -h \begin{vmatrix} \lambda-a & c \\ -d & f \end{vmatrix} +(\lambda-i) \begin{vmatrix} \lambda-a & -b \\ -d & \lambda-e \end{vmatrix} \nonumber \\ &=& -g[c(\lambda-e)+bf] \nonumber \\ & & -h[(\lambda-a)f+cd] \nonumber \\ & & +(\lambda-i)[(\lambda-a)(\lambda-e)-bd] \nonumber \\ &=& -cg(\lambda-e)-bfg \nonumber \\ & & -fh(\lambda-a)-cdh \nonumber \\ & & +(\lambda-a)(\lambda-e)(\lambda-i)-bd(\lambda-i) \nonumber \\ &=& 0 \label{eq.check_eigenvector_3} \end{eqnarray}\] となって\(\nu_3=0\)か否かに関わらず解が固有ベクトルになっていることが分かる。 ここで(\ref{eq.check_eigenvector_3})式の最後の等号では 固有値方程式(\ref{eq.eigenEquation})を用いた。
In the derivation of this solution, eqs (\ref{eq.nu1_nu3_relation}) and (\ref{eq.nu2_nu3_relation}) were used. What happens if the denominators in (\ref{eq.nu1_nu3_relation}) and (\ref{eq.nu2_nu3_relation}) are zero? This case corresponds to \(\nu_3=0\), and even in this case, the solutions (\ref{eq.nu3})-(\ref{eq.nu1}) satisfy the requirements (\ref{eq.eigenvector_relation.1})-(\ref{eq.eigenvector_relation.3}). Indeed, substituting the solutions (\ref{eq.nu3})-(\ref{eq.nu1}) into (\ref{eq.eigenvector_relation.1})-(\ref{eq.eigenvector_relation.3}) gives (\ref{eq.check_eigenvector_1})-(\ref{eq.check_eigenvector_3}), indicating that the solutions are indeed eigenvectors regardless of whether \(\nu_3=0\). In the last line of eq. (\ref{eq.check_eigenvector_3}), the eigenvalue equation (\ref{eq.eigenEquation}) was used.


◆検証(Validation)

行列 \[\begin{equation} {\bf A}= \begin{pmatrix} 1.2 & 3.4 & 5.6 \\ 7.8 & 9.0 & 12.3 \\ 45.6 & -78.9 & 9.1 \end{pmatrix} \label{eq.matrix_for_validation} \end{equation}\] の固有値・固有ベクトルをこの関数を用いて計算したところ、以下の結果となった (番号は以下の説明用に付けたものである)。
The eigenvalues and eigenvectors for a matrix of eq. (\ref{eq.matrix_for_validation}) calculated with this function was as follows (here, the numbers were added for the description below):

No. 固有値
Eigenvalue
固有ベクトル Eigenvector
1 \(11.27670+27.17391i\) \[\begin{equation*} \begin{pmatrix} 0.05992672+0.1671132i \\ 0.1840794+0.3670521i \\ -0.8148436+0.3686455i \end{pmatrix} \end{equation*}\]
2 \(11.27670-27.17391i\) \[\begin{equation*} \begin{pmatrix} 0.05992672-0.1671132i \\ 0.1840794-0.3670521i \\ -0.8148436-0.3686455i \end{pmatrix} \end{equation*}\]
3 \(-3.253393\) \[\begin{equation*} \begin{pmatrix} -0.6641723 \\ -0.2750155 \\ 0.6951558 \end{pmatrix} \end{equation*}\]

これらが実際に固有値・固有ベクトルになっていることは 上記の解を(\ref{eq.eigenvector_relation})式の左辺・右辺に代入して 比較して確かめられる。実際、固有値1, 2に対しては \[\begin{eqnarray} \begin{pmatrix} a & b & c \\ d & e & f \\ g & h & i \end{pmatrix} \begin{pmatrix} \nu_1 \\ \nu_2 \\ \nu_3 \end{pmatrix} &=& \begin{pmatrix} 1.2 & 3.4 & 5.6 \\ 7.8 & 9.0 & 12.3 \\ 45.6 & -78.9 & 9.1 \end{pmatrix} \begin{pmatrix} 0.05992672\pm 0.1671132i \\ 0.1840794\pm 0.3670521i \\ -0.8148436\pm 0.3686455i \end{pmatrix} \nonumber \\ &=& \begin{pmatrix} -3.865342\pm 3.512928i \\ -7.898433\pm 9.141292i \\ -19.20628\mp 17.98537i \end{pmatrix} \label{eq.validation.left12} \end{eqnarray}\] \[\begin{eqnarray} \lambda \begin{pmatrix} \nu_1 \\ \nu_2 \\ \nu_3 \end{pmatrix} &=& (11.27670\pm 27.17391i) \begin{pmatrix} 0.05992672\pm 0.1671132i \\ 0.1840794\pm 0.3670521i \\ -0.8148436\pm 0.3686455i \end{pmatrix} \nonumber \\ &=& \begin{pmatrix} -3.865343\pm 3.512929i \\ -7.898433\pm 9.141293i \\ -19.20629\mp 17.98538i \end{pmatrix} \label{eq.validation.right12} \end{eqnarray}\] となって(\ref{eq.eigenvector_relation})式の両辺は丸め誤差の範囲で一致する。 また固有値3に対しては \[\begin{eqnarray} \begin{pmatrix} a & b & c \\ d & e & f \\ g & h & i \end{pmatrix} \begin{pmatrix} \nu_1 \\ \nu_2 \\ \nu_3 \end{pmatrix} &=& \begin{pmatrix} 1.2 & 3.4 & 5.6 \\ 7.8 & 9.0 & 12.3 \\ 45.6 & -78.9 & 9.1 \end{pmatrix} \begin{pmatrix} -0.6641723 \\ -0.2750155 \\ 0.6951558 \end{pmatrix} \nonumber \\ &=& \begin{pmatrix} 2.160813 \\ 0.8947329 \\ -2.261616 \end{pmatrix} \label{eq.validation.left3} \end{eqnarray}\] \[\begin{eqnarray} \lambda \begin{pmatrix} \nu_1 \\ \nu_2 \\ \nu_3 \end{pmatrix} &=& -3.253393 \begin{pmatrix} -0.6641723 \\ -0.2750155 \\ 0.6951558 \end{pmatrix} \nonumber \\ &=& \begin{pmatrix} 2.160814 \\ 0.8947335 \\ -2.261615 \end{pmatrix} \label{eq.validation.right3} \end{eqnarray}\] となってこの場合も(\ref{eq.eigenvector_relation})式の両辺は 丸め誤差の範囲で一致する。
It can be confirmed that these estimated values of eigenvalues and eigenvectors are indeed eigenvalues and eigenvectors by calculating the left and right hand sides of eq. (\ref{eq.eigenvector_relation}). Indeed, the both hand sides give the same values within a rounding error in case of the 1st and 2nd eigenvalues and eigenvectors (eqs \ref{eq.validation.left12} and \ref{eq.validation.right12}) and in case of the 3rd eigenvalues and eigenvectors (eqs \ref{eq.validation.left3} and \ref{eq.validation.right3}).