我是靠谱客的博主 生动小甜瓜,这篇文章主要介绍Eigen求解大型稀疏对称矩阵(Cholesky分解),现在分享给大家,希望可以做个参考。

参考自Eigen文档
代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <Eigen/Sparse> typedef Eigen::SparseMatrix<double> SpMat; typedef Eigen::Triplet<double> Trip; int main() { //设置Triplet列表,该列表可以表示稀疏矩阵 std::vector<Trip> tripletList(9); tripletList.push_back(Trip(0, 0, 10)); tripletList.push_back(Trip(0, 1, -2)); tripletList.push_back(Trip(0, 2, -2)); tripletList.push_back(Trip(1, 0, -2)); tripletList.push_back(Trip(1, 1, 10)); tripletList.push_back(Trip(1, 2, -1)); tripletList.push_back(Trip(2, 0, -2)); tripletList.push_back(Trip(2, 1, -1)); tripletList.push_back(Trip(2, 2, 3)); //用Triplet列表构造稀疏矩阵 SpMat mat(3, 3); mat.setFromTriplets(tripletList.begin(), tripletList.end()); //使用Cholesky分解矩阵mat(LDLT分解) Eigen::SimplicialLDLT<SpMat> chol(mat); //构造右端项 Eigen::VectorXd b(3); b.coeffRef(0) = 1.0; b.coeffRef(1) = 0.5; b.coeffRef(2) = 1.0; //求解方程,回代 Eigen::VectorXd x = chol.solve(b); //输出结果 for (int i = 0; i < 3; i++) { std::cout << x.coeffRef(i) << std::endl; } return 0; }

最后

以上就是生动小甜瓜最近收集整理的关于Eigen求解大型稀疏对称矩阵(Cholesky分解)的全部内容,更多相关Eigen求解大型稀疏对称矩阵(Cholesky分解)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部