関数solution_LU マニュアル

(The documentation of function solution_LU)

Last Update: 2021/12/6


◆機能・用途(Purpose)

LU分解を用いて連立1次方程式 \[\begin{equation} \myvector{A}\myvector{x}=\myvector{b} \label{eq.problem} \end{equation}\] (\(\myvector{A}\):既知の正方行列、\(\myvector{b}\):既知の列ベクトル、 \(\myvector{x}\):未知の列ベクトル)を解く。 係数行列\(\myvector{A}\)そのものを与えるバージョン。
Solve a simultaneous linear equation (\ref{eq.problem}) using an LU decomposition, where \(\myvector{A}\) is a known square matrix, \(\myvector{b}\) is a known column vector, and \(\myvector{x}\) is an unknown column vector. In this function, the coefficient matrix \(\myvector{A}\) itself is given.


◆形式(Format)

#include <matrix/inverse.h>
inline struct columnvector solution_LU
(const struct matrix A,const struct columnvector b)


◆引数(Arguments)

A 連立方程式の左辺の係数行列。 (\ref{eq.problem})式の\(\myvector{A}\)。
A matrix composed of the coefficients in the left hand side of the simultaneous equation; the matrix \(\myvector{A}\) of eq. (\ref{eq.problem}).
b 連立方程式の右辺の定数ベクトル。 (\ref{eq.problem})式の\(\myvector{b}\)。
A vector composed of the constants in the right hand side of the simultaneous equation; the column vector \(\myvector{b}\) of eq. (\ref{eq.problem}).


◆戻り値(Return value)

方程式(\ref{eq.problem})の解\(\myvector{x}\)を表す列ベクトル。
A column vector representing the solution \(\myvector{x}\) of eq. (\ref{eq.problem}).


◆使用例(Example)

struct matrix A;
struct columnvector b;
struct columnvector x=solution_LU(A,b);


◆検証(validation)

この関数が実際に正しい結果を与えるか否かの検証のため、 \(\myvector{A}\), \(\myvector{b}\)を乱数を用いて生成し、 この関数を用いて\(\myvector{x}\)を求めた後、 \(\myvector{A}\myvector{x}\)を計算して \(\myvector{b}\)と一致するかをチェックした。 \(\myvector{A}\myvector{x}\)の計算には 関数matrix_times_columnvector (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 matrix_times_columnvector (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 \end{pmatrix} \end{equation*}\] \[\begin{equation*} \myvector{x}= \begin{pmatrix} -2.445247e-01 \\ -2.285589e+00 \\ -1.864861e+00 \\ -3.749452e+00 \end{pmatrix} \end{equation*}\] \[\begin{equation*} \myvector{A}\myvector{x}= \begin{pmatrix} 7.325038e-10 \\ 6.491890e-10 \\ 3.288509e-09 \\ 7.671914e-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 notes)

この関数の中で実際にやっていることは
  1. 関数LU_decomposition (matrix/inverse.h)を用いて \(\myvector{A}\)をLU分解する、
  2. その結果を関数solution_LU_givenLUdecomposition (matrix/inverse.h)に入力して 解を求める、
という2つの処理である。すなわち
struct matrix A;
struct columnvector b;
struct LU AA_LU=LU_decomposition(A);
struct columnvector x=solution_LU_givenLUdecomposition(AA_LU,b);
と書いてもこの関数を用いて行列式を計算したのと全く同じ結果が得られる。 LU分解を利用する計算を複数行う場合にはこの書き方をする方が LU分解を複数回行わずに済む分だけ効率が良い。
Within this function, the following two procedures are conducted:
  1. LU decomposition of \(\myvector{A}\) using the function LU_decomposition (matrix/inverse.h), and
  2. solving the equation using the LU decomposition result as the input, through the function solution_LU_givenLUdecomposition (matrix/inverse.h).
Therefore, writing the following code will results in exactly the same value as what is obtained by this function:
struct matrix A;
struct columnvector b;
struct LU AA_LU=LU_decomposition(A);
struct columnvector x=solution_LU_givenLUdecomposition(AA_LU,b);
When another calculation using the LU decomposition will be needed, the coding as above would be more efficient, since the LU decomposition is needed only once.