Skip to main content
edited tags
Link
Christian Clason
  • 12.4k
  • 3
  • 49
  • 68
Tweeted twitter.com/#!/StackSciComp/status/304899180629995520
Source Link
NoahR
  • 253
  • 2
  • 4

solve $xA=b$ for $x$ using LAPACK and BLAS

I am porting an existing code from MATLAB to C++ and have a linear system to solve $xA=b$ (rather than the more typical form $Ax=b$)

The matrix $A$ is dense, and of general form, but is no larger than 1000x1000. So in MATLAB, the solution is found by the mrdivide(b,A) function or the forward-slash notation x = b/A;

How should I solve this in my C++ code using BLAS and LAPACK routines?

I'm familiar with the LAPACK routine DGESV which solves $Ax=b$ for $x$.

So, one thought I had is to do some manipulations using matrix transpose identities:

$(xA)^T=b^T$

$A^T x^T = b^T$

$x^T = (A^T)^{-1} b^T$

Then solve the final form using DGESV operating on the transposed $A^T$. (so cost to transpose $A$ and cost to solve system)

Is there an approach more efficient or otherwise better?

I am working with matrix and vector classes as well as BLAS implementation from the BOOST uBLAS library as well as bindings to the LAPACK library routines. I've been using this setup successfully for other operations and am hoping to find a solution limited to these libraries.

Also, I should note I am only performing this type of operation a few times during code setup, so performance is not a critical concern.

Maybe this MATLAB documentation on mrdivide is helpful for others.