関数solution_QR マニュアル

(The documentation of function solution_QR)

Last Update: 2021/12/6


◆機能・用途(Purpose)

連立一次方程式の解および逆行列をQR分解を用いて計算する。
Calculate the solution of a simultaneous linear equation or an inverse matrix using a QR decomposition.


◆形式(Format)

#include <matrix/inverse.h>
inline struct matrix solution_QR
(const struct matrix A,const struct matrix B)


◆引数(Arguments)

A 連立方程式の係数行列\(\myvector{A}\)。正方行列でなければならない。
A matrix \(\myvector{A}\) composed of the coefficients of the simultaneous equation. This matrix must be a square matrix.
B 連立方程式の右辺から成る行列\(\myvector{B}\)。 行数は\(\myvector{A}\)の行数と等しくなければならないが列数は任意である。 例えば\(\myvector{B}\)の列数を1にすれば連立一次方程式の解の計算になる。 また\(\myvector{B}\)を単位正方行列にした場合には \(\myvector{A}\)の逆行列の計算になる。
A matrix composed of the right hand side of the simultaneous equation. The number of rows of this matrix must be equal to that of \(\myvector{A}\), and the number of columns is arbitrary. For example, if \(\myvector{B}\) has only one column, then the problem reduces to solving a simultaneous equation. If a unit square matrix is used for \(\myvector{B}\), then the problem reduces to calculation of the inverse of \(\myvector{A}\).


◆戻り値(Return value)

方程式\(\myvector{A}\myvector{X}=\myvector{B}\)の解\(\myvector{X}\)。 行列\(\myvector{A}\)のランク\(p\)が\(\myvector{A}\)の行数よりも小さい場合には \(\myvector{X}\)の\(p+1\)行目以降を0とした解が返される。
The solution \(\myvector{X}\) of an equation \(\myvector{A}\myvector{X}=\myvector{B}\). When the rank \(p\) of the matrix \(\myvector{A}\) is less than the number of rows of it, then the solution \(\myvector{X}\) will have the value 0 for all the components after (\(p+1\))th raw.


◆使用例(Example)

struct matrix A=get_matrix_memory(2,2);
struct matrix I2=unit_matrix(2);
A.main[0][0]=1.0;
A.main[0][1]=2.0;
A.main[1][0]=3.0;
A.main[1][1]=4.0;
struct matrix Ainv=solution_QR(A,I2);


◆検証(Validation)

この関数が実際に正しい結果を与えるか否かの検証のため、 \(\myvector{A}\), \(\myvector{B}\)を乱数を用いて生成し、 この関数を用いて\(\myvector{X}\)を求めた後、 \(\myvector{A}\myvector{X}\)を計算して \(\myvector{B}\)と一致するかをチェックした。 \(\myvector{A}\myvector{X}\)の計算には 関数multiply_matrix (matrix/operation.h)を用いた。 結果は以下の通りであった。
To examine if this function gives a correct result, \(\myvector{A}\) and \(\myvector{B}\) were generated by random values, and \(\myvector{X}\) was calculated using this function, and then \(\myvector{A}\myvector{X}\) was calculated and compared with \(\myvector{B}\). Function multiply_matrix (matrix/operation.h) was used for the calculation of \(\myvector{A}\myvector{X}\). The result was as follows.

\[\begin{equation*} \myvector{A}= \begin{pmatrix} -5.542348e-10 & 1.180734e-09 & -5.946389e-10 & -5.832139e-10 \\ -5.107910e-10 & -2.357166e-09 & 1.389110e-09 & 6.061486e-10 \\ -1.676399e-09 & -8.405894e-10 & 9.754172e-10 & -7.404720e-10 \\ 1.276538e-09 & -9.070130e-10 & -4.890220e-10 & 5.082556e-10 \end{pmatrix} \end{equation*}\] \[\begin{equation*} \myvector{B}= \begin{pmatrix} 7.325038e-10 & 6.491890e-10 \\ 3.288509e-09 & 7.671914e-10 \\ -2.856718e-08 & 1.917195e-09 \\ -3.393252e-09 & -5.790534e-10 \end{pmatrix} \end{equation*}\] \[\begin{equation*} \myvector{X}= \begin{pmatrix} -2.778448e+01 & -1.360895e+00 \\ 1.097511e+01 & -7.518685e-01 \\ -1.782558e+01 & -1.150001e+00 \\ 6.554215e+01 & -1.694993e-01 \end{pmatrix} \end{equation*}\] \[\begin{equation*} \myvector{A}\myvector{X}= \begin{pmatrix} 7.325038e-10 & 6.491890e-10 \\ 3.288509e-09 & 7.671914e-10 \\ -2.856718e-08 & 1.917195e-09 \\ -3.393252e-09 & -5.790534e-10 \end{pmatrix} \end{equation*}\] この結果から、\(\myvector{A}\myvector{X}\)と\(\myvector{B}\)は一致しており、 \(\myvector{X}\)を正しく求められたことが分かる。
In this result, \(\myvector{A}\myvector{X}\) is consistent with \(\myvector{B}\), indicating that \(\myvector{X}\) was solved correctly.


◆補足(Additional remarks)