示例#1
0
void
spSolve(char *eMatrix, RealVector  RHS, RealVector  Solution IMAG_VECTORS )
{
    MatrixPtr  Matrix = (MatrixPtr)eMatrix;
    register  ElementPtr  pElement;
    register  RealVector  Intermediate;
    register  RealNumber  Temp;
    register  int  I, *pExtOrder, Size;
    ElementPtr  pPivot;

    /* Begin `spSolve'. */
    ASSERT( IS_VALID(Matrix) AND IS_FACTORED(Matrix) );

#if spCOMPLEX
    if (Matrix->Complex)
    {
        SolveComplexMatrix( Matrix, RHS, Solution IMAG_VECTORS );
        return;
    }
#endif

#if REAL
    Intermediate = Matrix->Intermediate;
    Size = Matrix->Size;

    /* Correct array pointers for ARRAY_OFFSET. */
#if NOT ARRAY_OFFSET
    --RHS;
    --Solution;
#endif

    /* Initialize Intermediate vector. */
    pExtOrder = &Matrix->IntToExtRowMap[Size];
    for (I = Size; I > 0; I--)
    {
        Intermediate[I] = RHS[*(pExtOrder--)];
    }

    /* Forward elimination. Solves Lc = b.*/
    for (I = 1; I <= Size; I++)
    {

        /* This step of the elimination is skipped if Temp equals zero. */
        if ((Temp = Intermediate[I]) != 0.0)
        {
            pPivot = Matrix->Diag[I];
            if ( pPivot != 0 && ELEMENT_MAG(pPivot) >  Matrix->AbsThreshold )
            {
                /*jpc    Intermediate[I] = (Temp *= pPivot->Real);*/
                Intermediate[I] = (Temp /= pPivot->Real);

                pElement = pPivot->NextInCol;
                while (pElement != NULL)
                {
                    Intermediate[pElement->Row] -= Temp * pElement->Real;
                    pElement = pElement->NextInCol;
                }
            }
            else
            {
                Intermediate[I] = 0.0;
            }
        }
    }

    /* Backward Substitution. Solves Ux = c.*/
    /* modification for singular matrix a diagonal element can be a null pointer */

    for (I = Size ; I > 0; I--)
    {
        Temp = Intermediate[I];
        if ( Matrix->Diag[I] == 0) /* test for nul pointer */
        {
            Intermediate[I] = 0.0;
        }
        else
        {
            pElement = Matrix->Diag[I]->NextInRow;
            while (pElement != NULL)
            {
                Temp -= pElement->Real * Intermediate[pElement->Col];
                pElement = pElement->NextInRow;
            }
            Intermediate[I] = Temp;
        }
    }

    /* Unscramble Intermediate vector while placing data in to Solution vector. */
    pExtOrder = &Matrix->IntToExtColMap[Size];
    for (I = Size; I > 0; I--)
    {
        Solution[*(pExtOrder--)] = Intermediate[I];
    }

    return;
#endif /* REAL */
}
示例#2
0
void
spSolveTransposed( char *eMatrix, RealVector  RHS, RealVector  Solution IMAG_VECTORS )
{
    MatrixPtr  Matrix = (MatrixPtr)eMatrix;
    register  ElementPtr  pElement;
    register  RealVector  Intermediate;
    register  int  I, *pExtOrder, Size;
    ElementPtr  pPivot;
    RealNumber  Temp;


    /* Begin `spSolveTransposed'. */
    ASSERT( IS_VALID(Matrix) AND IS_FACTORED(Matrix) );

#if spCOMPLEX
    if (Matrix->Complex)
    {
        SolveComplexTransposedMatrix( Matrix, RHS, Solution IMAG_VECTORS );
        return;
    }
#endif

#if REAL
    Size = Matrix->Size;
    Intermediate = Matrix->Intermediate;

    /* Correct array pointers for ARRAY_OFFSET. */
#if NOT ARRAY_OFFSET
    --RHS;
    --Solution;
#endif

    /* Initialize Intermediate vector. */
    pExtOrder = &Matrix->IntToExtColMap[Size];
    for (I = Size; I > 0; I--)
    {
        Intermediate[I] = RHS[*(pExtOrder--)];
    }

    /* Forward elimination. */
    for (I = 1; I <= Size; I++)
    {
        /* This step of the elimination is skipped if Temp equals zero. */
        if ((Temp = Intermediate[I]) != 0.0)
        {
            pElement = Matrix->Diag[I]->NextInRow;
            while (pElement != NULL)
            {
                Intermediate[pElement->Col] -= Temp * pElement->Real;
                pElement = pElement->NextInRow;
            }

        }
    }

    /* Backward Substitution. */
    for (I = Size; I > 0; I--)
    {
        pPivot = Matrix->Diag[I];
        Temp = Intermediate[I];
        pElement = pPivot->NextInCol;
        while (pElement != NULL)
        {
            Temp -= pElement->Real * Intermediate[pElement->Row];
            pElement = pElement->NextInCol;
        }
        Intermediate[I] = Temp * pPivot->Real;
    }

    /* Unscramble Intermediate vector while placing data in to Solution vector. */
    pExtOrder = &Matrix->IntToExtRowMap[Size];
    for (I = Size; I > 0; I--)
    {
        Solution[*(pExtOrder--)] = Intermediate[I];
    }

    return;
#endif /* REAL */
}
示例#3
0
void
spSolveTransposed(MatrixPtr Matrix, RealVector RHS, RealVector Solution,
		  RealVector iRHS, RealVector iSolution)
{
    ElementPtr  pElement;
    RealVector  Intermediate;
    int  I, *pExtOrder, Size;
    ElementPtr  pPivot;
    RealNumber  Temp;

    /* Begin `spSolveTransposed'. */
    assert( IS_VALID(Matrix) && IS_FACTORED(Matrix) );

    if (Matrix->Complex)
    {
	SolveComplexTransposedMatrix( Matrix, RHS, Solution , iRHS, iSolution );
        return;
    }

    Size = Matrix->Size;
    Intermediate = Matrix->Intermediate;

    /* Initialize Intermediate vector. */
    pExtOrder = &Matrix->IntToExtColMap[Size];
    for (I = Size; I > 0; I--)
        Intermediate[I] = RHS[*(pExtOrder--)];

    /* Forward elimination. */
    for (I = 1; I <= Size; I++)
    {
   
	/* This step of the elimination is skipped if Temp equals zero. */
        if ((Temp = Intermediate[I]) != 0.0)
        {
	    pElement = Matrix->Diag[I]->NextInRow;
            while (pElement != NULL)
            {
		Intermediate[pElement->Col] -= Temp * pElement->Real;
                pElement = pElement->NextInRow;
            }

        }
    }

    /* Backward Substitution. */
    for (I = Size; I > 0; I--)
    {
	pPivot = Matrix->Diag[I];
        Temp = Intermediate[I];
        pElement = pPivot->NextInCol;
        while (pElement != NULL)
        {
	    Temp -= pElement->Real * Intermediate[pElement->Row];
            pElement = pElement->NextInCol;
        }
        Intermediate[I] = Temp * pPivot->Real;
    }

    /* Unscramble Intermediate vector while placing data in to
       Solution vector. */
    pExtOrder = &Matrix->IntToExtRowMap[Size];
    for (I = Size; I > 0; I--)
        Solution[*(pExtOrder--)] = Intermediate[I];

    return;
}