• 基于Eigen调用Pardiso求解线性方程组


     1 #include <Eigen/Sparse>
     2 #include <Eigen/IterativeLinearSolvers>
     3 #include <Eigen/PardisoSupport>
     4 using namespace Eigen;
     5 using namespace std;
     6 typedef Eigen::SparseMatrix<double> SpMat;
     7 typedef Eigen::PardisoLU <SpMat> PLUSolver;
     8 typedef Eigen::PardisoLDLT <SpMat> PLDLTSolver;
     9 
    10 //构造稀疏矩阵,按照行列号插入非零元素
    11 SpMat A(8, 8); 
    12 A.insert(0, 0) = 7.0; 
    13 A.insert(0, 2) = 1.0;
    14 ……
    15 A.makeCompressed();
    16 VectorXd b(8), x(8);
    //使用Eigen自带CG求解器求解对称稀疏矩阵线性方程组
    ConjugateGradient<SparseMatrix<double>, Eigen::Upper> solver;
    x = solver.compute(A).solve(b);
    //调用pardiso求解非对称稀疏矩阵线性方程组
    PLUSolver solver;
    solver.analyzePattern(A);
    solver.factorize(A);
    x = solver.solve(b);
    //调用pardiso求解对称稀疏矩阵线性方程组
    PLDLTSolver solver;
    solver.analyzePattern(A);
    solver.factorize(A);
    x = solver.solve(b);
  • 相关阅读:
    10.28作业
    10.27作业
    10.26作业
    10.22作业
    10.20作业
    10.19作业
    10.16作业
    10.15作业
    10.14作业
    10.13作业
  • 原文地址:https://www.cnblogs.com/dalanjing/p/13654226.html
Copyright © 2020-2023  润新知