Lagrangian Particle Code for The Simulation of 2D/3D Fluid Dynamics
 All Classes Files Functions Variables Typedefs Friends Pages
Public Member Functions | List of all members
QRSolver Class Reference

A class which solves the least squares problem by the QR decomposition method. More...

#include <ls_solver.h>

Inheritance diagram for QRSolver:
LSSolver

Public Member Functions

 QRSolver (std::size_t numRow, std::size_t numCol, double *A, double limitR=1e-3)
 Constructor. More...
 
virtual int solve (double *result, double *b)
 returns 0 if success and result will be non-empty returns k<0 if the kth argument is illegal, result is empty returns k>0, k=rank in this case, result is empty More...
 
- Public Member Functions inherited from LSSolver
virtual ~LSSolver ()
 Destructor. More...
 

Additional Inherited Members

- Protected Attributes inherited from LSSolver
std::size_t m_iNumRow
 The number of rows in matrix A.
 
std::size_t m_iNumCol
 The number of columns in matrix A.
 
double * m_vA
 The matrix A.
 
double * m_vb
 The vector b (the right-hand-side)
 

Detailed Description

A class which solves the least squares problem by the QR decomposition method.

Author
Chen, Hsin-Chiang (morri.nosp@m.sche.nosp@m.n2008.nosp@m.@gma.nosp@m.il.co.nosp@m.m)

Co-author: Yu, Kwangmin (yukwa.nosp@m.ngmi.nosp@m.n@gma.nosp@m.il.c.nosp@m.om) on initial interface design

Version
1.0
Date
2014/10/09

Created on: 2014/09/20

Constructor & Destructor Documentation

QRSolver::QRSolver ( std::size_t  numRow,
std::size_t  numCol,
double *  A,
double  limitR = 1e-3 
)
inline

Constructor.

Set up the matrix A and other scalar parameters of this class

Parameters
[in]numRowThe number of rows in matrix A
[in]numColThe number of columns in matrix A
[in]AThe matrix A
[in]limitRA specified scalar multiplier (<1) for trimming diagonal entry of R in the QR decomposition

Member Function Documentation

int QRSolver::solve ( double *  result,
double *  b 
)
virtual

returns 0 if success and result will be non-empty returns k<0 if the kth argument is illegal, result is empty returns k>0, k=rank in this case, result is empty

Solves the least squares problem Ax = b by the QR decomposition method

A is a mxn matrix, b is a mx1 vector, and x is the solution which is a nx1 vector This method solves for $ x $ by the following steps:

  1. Call the function LAPACKE_dgeqp3() in LAPACK to perform QR decomposition with column pivoting to obtain

    \[ QRPx = b \]

    where $ P $ is a permutation matrix
  2. Multiply both sides on the left by $ Q^T $ to get

    \[ RPx = Q^T b \]


  3. Use back substitution to get $ y = Px $
  4. Solves $ Px = y $ for $ x $
Parameters
[out]resultThe x in Ax = b, which is a nx1 vector
[in]bThe right-hand-size, which is a mx1 vector
Returns
0 if success; otherwise if failure
Warning
The input array b is modified in this method

Implements LSSolver.


The documentation for this class was generated from the following files: