简体   繁体   English

犰狳C ++ LU分解

[英]Armadillo C++ LU decomposition

I am using the Armadillo C++ library for solving linear systems of medium/large dimensions (1000-5000 equations). 我正在使用Armadillo C ++库来求解中/大尺寸(1000-5000个方程)的线性系统。

Since I have to solve different linear systems 由于我必须解决不同的线性系统

AX=b AX = b的

in which A is always the same and B changes, I would like to LU factorize A only once and reuse the LU factorization with different b. 在其中A始终相同而B发生变化的情况下,我只希望LU分解A一次,然后将LU分解重用不同的b。 Unfortunately I do not know how to perform this kind of operations in Armadillo. 不幸的是,我不知道如何在犰狳中执行这种操作。

What I did was just the LU factorization of the A matrix: 我所做的只是A矩阵的LU分解:

arma::mat A;
// ... fill the A matrix ...
arma::mat P,L,U;
arma::lu(L, U, P, A);

But now I would like to use the matrices P, L and U to solve several linear systems with different b vectors. 但是现在我想使用矩阵P,L和U来求解具有不同b向量的几个线性系统。

Could you help me please? 请问你能帮帮我吗?

Since A = Pt()*L*U (where equality is only approximate due to rounding errors), solving for x in Pt()*L*U*x = b requires to permute rows of B and performing forward and back substitution: 由于A = Pt()*L*U (其中的均等值仅由于舍入误差而近似),因此在Pt()*L*U*x = b求解x要求置换B行并执行正向和反向替换:

x = solve(trimatu(U), solve(trimatl(L), P*b) );

Due to the lack of a true triangular solver in armadillo, and a fast way to perform row permutation, this procedure will not be very efficient, with respect to a direct call to the relevant computational LAPACK subroutines. 由于犰狳中缺少真正的三角求解器,并且缺乏执行行置换的快速方法,因此,相对于直接调用相关的计算LAPACK子例程而言,此过程将不是很有效。

General advice is to avoid explicit LU decomposition in higher level libraries, like armadillo. 一般建议是避免在更高版本的库(如犰狳)中进行显式LU分解。

  1. if all different b 's are known at the same time, store them as columns in a rectangular matrix B and X = solve(A,B); 如果同时知道所有不同的b ,则将它们作为列存储在矩形矩阵B并且X = solve(A,B);
  2. if the different b 's are known one at a time, then precomputing AINV = Ai(); 如果一次知道不同的b ,则预先计算AINV = Ai(); and x = AINV*b; 并且x = AINV*b; will be more efficient if the number of different rhs vectors is big enough. 如果不同的rhs向量的数量足够大,将更加有效。 See this answer to a similar question . 看到类似问题的 答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM