我在C++程序上使用Eigen来求解非常小的方阵(4X4)的线性方程.
我的测试代码就像
template<template <typename MatrixType> typename EigenSolver>
Vertor3d solve(){
//Solve Ax = b and A is a real symmetric matrix and positive semidefinite
... // Construct 4X4 square matrix A and 4X1 vector b
EigenSolver<Matrix4d> solver(A);
auto x = solver.solve(b);
... // Compute relative error for validating
}
Run Code Online (Sandbox Code Playgroud)
我测试了一些EigenSolver,其中包括:
直接反转是:
template<typename MatrixType>
struct InverseSolve
{
private:
MatrixType inv;
public:
InverseSolve(const MatrixType &matrix) :inv(matrix.inverse()) {
}
template<typename VectorType>
auto …Run Code Online (Sandbox Code Playgroud)