2017-03-07 105 views
0

现在我想用C++ Boost来求解矩阵函数:A * P = X,P = A \ X。我有矩阵A和矩阵X,所以我需要做P = A \ X来得到矩阵P.这是一个矩阵划分问题,对吗?使用C++ Boost的矩阵分割

我的C++代码是

#include "stdafx.h" 
#include <boost\mat2cpp-20130725/mat2cpp.hpp> 
#include <boost/numeric/ublas/matrix.hpp> 
#include <boost/numeric/ublas/matrix_proxy.hpp> 
#include <boost/numeric/ublas/io.hpp> 
using namespace boost::numeric::ublas; 
using namespace std; 

int main() { 
    using namespace mat2cpp; 
    matrix<double> x(2,2); // initialize a matrix 
    x(0, 0) = 1; // assign value 
    x(1, 1) = 1; 
    matrix<double> y(2, 1); 
    y(0, 0) = 1; 
    y(1, 0) = 1; 

    size_t rank; 
    matrix<double> z = matrix_div(x, y, rank); 
} 

但它有错误Error figure,请帮帮我!谢谢!

+0

可能重复[什么是未定义的引用/无法解析的外部符号错误,以及如何解决它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved- external-symbol-error-and-how-do-i-fix) –

+0

我在我的Boost发行版(1.63)中找不到'boost \ mat2cpp-20130725/mat2cpp.hpp'。你使用什么版本? – TobiMcNamobi

+0

Google发现三(3)页字符串为“mat2cpp-20130725”。其中之一就是这个问题。另外两个表明这个目录不是提升的一部分。 –

回答

1

首先,没有像矩阵分割这样的事情。如果你有这个方程A * P = X并且你想找到P,那么解决方案是:inv(A)* A * P = inv(A)* X,其中inv(A)是A矩阵的逆矩阵。因为我们知道inv(A)* A等于单位矩阵,所以我们可以得出结论:P = inv(A)* X.

现在你的问题是计算A矩阵的逆。有几种方法可以做到这一点,我的建议是使用LU分解。

老实说,我不知道增强库是否有mat2cpp这样的东西。如果你想使用提升,我会建议使用boost/numeric/ublas/matrix.hpp

+0

很好的答案。我想添加“计算逆* ...如果它存在*”。除了[uBLAS](http://www.boost.org/doc/libs/1_63_0/libs/numeric/ublas/doc/index.html)之外,Boost还包含名为[QVM]的库(http:// www .boost.org/doc/libs/1_63_0/libs/qvm/doc/index.html),我最近使用它来计算(小)矩阵的逆。 – TobiMcNamobi