【发布时间】:2018-10-03 12:28:32
【问题描述】:
我想从矩阵中提取线性组合,但通过执行模数组合。
让我们考虑计算模数 5,然后我们有以下相加:
+ | 0 1 2 3 4
--+-----------
0 | 0 1 2 3 4
1 | 1 2 3 4 0
2 | 2 3 4 0 1
3 | 3 4 0 1 2
4 | 4 0 1 2 3
和这个表的乘法:
* | 0 1 2 3 4
--+-----------
0 | 0 0 0 0 0
1 | 0 1 2 3 4
2 | 0 2 4 1 3
3 | 0 3 1 4 2
4 | 0 4 3 2 1
让我们举个例子: 让我们考虑以下矩阵:
E = 2 1 3 2 0
4 3 0 1 1
然后我们可以通过LU分解(https://en.wikipedia.org/wiki/LU_decomposition)(或高斯消元法)得到三角剖分矩阵,如下:
T = 1 0 0 0 0
2 1 0 0 0
最后是我要提取的矩阵,也就是存储线性组合的矩阵:
CL = 3 2 3 0 3
0 1 1 3 4
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
所以基本上,算法应该如下工作:
Input: a matrix E with n rows and m columns, and p, a prime number.
* We perform a Gaussian elimination/LU decomposition to obtain the lower-triangulation matrix T.
But all the calculus are done modulo 'p'.
Output: T (with the same size as E, n rows m columns).
CL (with a size m rows, m columns),
which is basically the identity matrix on which we
applied all the modifications that were performed on E to obtain T.
好的,现在我们有了上下文,让我解释一下问题。
我开始使用 Armadillo 库 (http://arma.sourceforge.net/) 来做这件事,但我没有在库上找到任何解决方案来对数学字段 p 执行微积分。我很容易找到LU的方法来获取下三角矩阵,但是计算是在真实中进行的。
#include <iostream>
#include <armadillo>
using namespace arma;
using namespace std;
int main(int argc,char** argv)
{
mat A = mat({{2,1,3,2,0},{4,3,0,1,1}});
mat L, U, P;
lu(L, U, P, A);
cout << L << endl;
return 0;
}
通过以下方法,您可以获得下三角矩阵“L”,但在实际微积分中。从而获得:
T' = 1 0
1/2 1
是否有任何技术可以以模数方式执行计算?
编辑 Armadillo 库无法做到这一点。我开发了自己的 LU 模数分解,但那里仍然存在错误。我在这里Linear Combination C++ in modulus提出了一个新问题,希望能解决。
【问题讨论】:
标签: c++ matrix linear-algebra armadillo