5 #ifndef SPIDAR_CHOLESKY_HPP 6 #define SPIDAR_CHOLESKY_HPP 21 template <
class MatrixType>
24 template <
class MatrixType,
class VectorType>
25 static void solve(MatrixType& mat, VectorType& vec);
34 template <
class MatrixType>
37 static_assert(MatrixType::row==MatrixType::column,
"row != column");
39 const size_t size = MatrixType::row;
41 for(
size_t j=0; j<size; ++j)
44 for (
size_t k=0; k<j; ++k)
46 mat[j][j] -= mat[j][k] * mat[j][k];
48 mat[j][j] = std::sqrt(mat[j][j]);
51 for (
size_t i=0; i<j; ++i)
57 for (
size_t i=j+1; i<size; ++i)
59 for (
size_t k=0; k<j; ++k)
61 mat[i][j] -= mat[i][k] * mat[j][k];
63 mat[i][j] /= mat[j][j];
74 template <
class MatrixType,
class VectorType>
77 static_assert(MatrixType::row==MatrixType::column,
"row != column");
78 static_assert(MatrixType::row==VectorType::size,
"matrix size != vector size");
80 const size_t size = VectorType::size;
86 for (
size_t i=0; i<size; ++i)
88 for (
size_t k=0; k<i; ++k)
90 vec[i] -= vec[k] * mat[i][k];
96 for (
size_t i=size-1; i<size; --i)
98 for (
size_t k=i+1; k<size; ++k)
100 vec[i] -= vec[k] * mat[k][i];
109 #endif // SPIDAR_CHOLESKY_HPP
static void decompose(MatrixType &mat)
コレスキー分解を行います.
static void solve(MatrixType &mat, VectorType &vec)
コレスキー分解を用いて連立一次方程式を解きます.