main/sc/source/core/tool/interpr5.cxx
/* Calculates a QR decomposition with Householder reflection.
 * For each NxK matrix A exists a decomposition A=Q*R with an orthogonal
 * NxN matrix Q and a NxK matrix R.
 * Q=H1*H2*...*Hk with Householder matrices H. Such a householder matrix can
 * be build from a vector u by H=I-(2/u'u)*(u u'). This vectors u are returned
 * in the columns of matrix A, overwriting the old content.
 * The matrix R has a quadric upper part KxK with values in the upper right
 * triangle and zeros in all other elements. Here the diagonal elements of R
 * are stored in the vector R and the other upper right elements in the upper
 * right of the matrix A.
 * The function returns false, if calculation breaks. But because of round-off
 * errors singularity is often not detected.
 */
Calculates a QR decomposition with Householder reflection.
For each NxK matrix A exists a decomposition A=Q*R with an orthogonal
NxN matrix Q and a NxK matrix R.
Q=H1*H2*...*Hk with Householder matrices H. Such a householder matrix can
be build from a vector u by H=I-(2/u'u)*(u u'). This vectors u are returned
in the columns of matrix A, overwriting the old content.
The matrix R has a quadric upper part KxK with values in the upper right
triangle and zeros in all other elements. Here the diagonal elements of R
are stored in the vector R and the other upper right elements in the upper
right of the matrix A.
The function returns false, if calculation breaks. But because of round-off
errors singularity is often not detected.
Calculates a QR decomposition with Householder reflection . For each NxK matrix A exists a decomposition A = Q * R with an orthogonal NxN matrix Q and a NxK matrix R . Q = H1 * H2 * ... * Hk with Householder matrices H . Such a householder matrix can be build from a vector u by H = I - ( 2 / u ' u ) * ( u u ' ) . This vectors u are returned in the columns of matrix A overwriting the old content . The matrix R has a quadric upper part KxK with values in the upper right triangle and zeros in all other elements . Here the diagonal elements of R are stored in the vector R and the other upper right elements in the upper right of the matrix A . The function returns false if calculation breaks . But because of round - off errors singularity is often not detected .
bool lcl_CalculateQRdecomposition(ScMatrixRef pMatA,
                    ::std::vector< double>& pVecR, SCSIZE nK, SCSIZE nN)
{
    double fScale ;
    double fEuclid ;
    double fFactor ;
    double fSignum ;
    double fSum ;
    for (SCSIZE col = 0; col <nK; col++)
    {
        fScale = lcl_GetColumnMaximumNorm(pMatA, col, col, nN);
        if (fScale == 0.0)
            return false;
        for (SCSIZE row = col; row <nN; row++)
            pMatA->PutDouble( pMatA->GetDouble(col,row)/fScale, col, row);
        fEuclid = lcl_GetColumnEuclideanNorm(pMatA, col, col, nN);
        fFactor = 1.0/fEuclid/(fEuclid + fabs(pMatA->GetDouble(col,col)));
        fSignum = lcl_GetSign(pMatA->GetDouble(col,col));
        pMatA->PutDouble( pMatA->GetDouble(col,col) + fSignum*fEuclid, col,col);
        pVecR[col] = -fSignum * fScale * fEuclid;
        for (SCSIZE c=col+1; c<nK; c++)
        {
            fSum =lcl_GetColumnSumProduct(pMatA, col, pMatA, c, col, nN);
            for (SCSIZE row = col; row <nN; row++)
                pMatA->PutDouble( pMatA->GetDouble(c,row)
                        - fSum * fFactor * pMatA->GetDouble(col,row), c, row);
        }
    }
    return true;
}
bool lcl_CalculateQRdecomposition ( ScMatrixRef pMatA , :: std :: vector < double > & pVecR , SCSIZE nK , SCSIZE nN ) { double fScale ; double fEuclid ; double fFactor ; double fSignum ; double fSum ; for ( SCSIZE col = 0 ; col < nK ; col ++ ) { fScale = lcl_GetColumnMaximumNorm ( pMatA , col , col , nN ) ; if ( fScale == 0.0 ) return false ; for ( SCSIZE row = col ; row < nN ; row ++ ) pMatA -> PutDouble ( pMatA -> GetDouble ( col , row ) / fScale , col , row ) ; fEuclid = lcl_GetColumnEuclideanNorm ( pMatA , col , col , nN ) ; fFactor = 1.0 / fEuclid / ( fEuclid + fabs ( pMatA -> GetDouble ( col , col ) ) ) ; fSignum = lcl_GetSign ( pMatA -> GetDouble ( col , col ) ) ; pMatA -> PutDouble ( pMatA -> GetDouble ( col , col ) + fSignum * fEuclid , col , col ) ; pVecR [ col ] = - fSignum * fScale * fEuclid ; for ( SCSIZE c = col + 1 ; c < nK ; c ++ ) { fSum = lcl_GetColumnSumProduct ( pMatA , col , pMatA , c , col , nN ) ; for ( SCSIZE row = col ; row < nN ; row ++ ) pMatA -> PutDouble ( pMatA -> GetDouble ( c , row ) - fSum * fFactor * pMatA -> GetDouble ( col , row ) , c , row ) ; } } return true ; }
Calculates a QR decomposition with Householder reflection.
Calculates a QR decomposition with Householder reflection .
// ScMatrix matrices are zero based, index access (column,row) // calculate vector u of the householder transformation // A is singular // apply Householder transformation to A