我正在使用EIGEN稀疏库来解决系统问题。我尝试在较小的矩阵上进行测试,估计误差接近于零。我附上以下代码的片段。
MatrixXd Dense(4,4);
Dense<<2.0,0.0,0.0,0.0,
0.0,1.0,0.0,1.0,
0.0,0.0,5.0,0.0,
0.0,0.0,0.0,1.0;
Vector4d b(4.0, 5.0, 8.0, 1.0),xsol;
cout << "The least-squares solution is:\n"
<< Dense.jacobiSvd(ComputeThinU | ComputeThinV).solve(b) << endl;
SpMat SparseA;
SparseA = Dense.sparseView();
cout<<SparseA<<endl;
BiCGSTAB<SparseMatrix<double> > bicg;
bicg.compute(SparseA);
xsol = bicg.solve(b);
std::cout << "#iterations: " << bicg.iterations() << std::endl;
std::cout << "estimated error: " << bicg.error() << std::endl;
// update and solve again
xsol = bicg.solve(b);
cout << "Sparse Matrix Solution is:\n" << xsol << endl;**
这是我运行代码时得到的结果:
迭代:1
估计错误:0
稀疏矩阵解决方案是:
2 4 1.6 1
现在问题是我扩大了系统并试图解决我得到巨大的估计错误。我该如何解决这个问题。顺便说一句,我遵循定义密集矩阵的相同过程,并在求解系统之前将它们转换为稀疏矩阵。代码段如下
typedef Eigen::SparseMatrix<double> SpMat;
SpMat SparseKGl;
VectorXd wsol;
SparseKGl = KGl.sparseView();
BiCGSTAB<SparseMatrix<double> > bicg;
wsol=bicg.compute(SparseKGl).solve(ForceGl);
std::cout << "iterations: " << bicg.iterations() << std::endl;
std::cout << "estimated error: " << bicg.error() << std::endl;
// update and solve again
wsol = bicg.solve(ForceGl);
我得到的输出是
迭代:22
估计错误:70549
任何人都可以提供相同的见解吗?
此致