如何在特征库中计算稀疏矩阵的逆 [英] How can I calculate inverse of sparse matrix in Eigen library

查看:540
本文介绍了如何在特征库中计算稀疏矩阵的逆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C ++中的本征库有疑问.实际上,我想计算稀疏矩阵的逆矩阵. 当我在Eigen中使用密集矩阵时,可以使用.inverse()操作来计算密集矩阵的逆. 但是在稀疏矩阵中,我无法在任何地方找到逆运算.有谁知道计算稀疏矩阵的逆吗?帮我.

I have a question about Eigen library in C++. Actually, I want to calculate inverse matrix of sparse matrix. When I used Dense matrix in Eigen, I can use .inverse() operation to calculate inverse of dense matrix. But in Sparse matrix, I cannot find inverse operation anywhere. Does anyone who know to calculate inverse of sparse matrix? help me.

推荐答案

您不能直接执行此操作,但始终可以使用稀疏求解器之一对其进行计算.想法是解决A*X=I,其中I是单位矩阵.如果有解决方案,则X将是您的逆矩阵. 本征文档上有关于稀疏求解器及其使用方法的页面,但是基本步骤如下:

You cannot do it directly, but you can always calculate it, using one of the sparse solvers. The idea is to solve A*X=I, where I is the identity matrix. If there is a solution, X will be your inverse matrix. The eigen documentation has a page about sparse solvers and how to use them, but the basic steps are as follows:

SolverClassName<SparseMatrix<double> > solver;
solver.compute(A);
SparseMatrix<double> I(n,n);
I.setIdentity();
auto A_inv = solver.solve(I);

这篇关于如何在特征库中计算稀疏矩阵的逆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆