*/
Love this site? Hate it? Leave us some comments.
*/

View \xdet4.h

Application of the identity matrix II. v05

Submitted By: xhunga
Rating: starstar (Rate It)


/* xdet4.h                      freeware                   [[Email Removed]]  */


/* --------------------------------- FUNCTION ------------------------------  */
/* Do    :                                                                    */
/*                                                                            */
/* Call  :                                                                    */
/* Debug :                                                                    */
/* -------------------------------------------------------------------------- */
fraction cofactorF(
pmatrix mA,
int ci,
int cj)
{
     int i;
     int j;
     int n;
     int tci = 0;
     int tcj = 0;
fraction f;

double pMinor [MXR][MXC*TWOCOL];matrix mMinor ={MXR,MXC*TWOCOL,&pMinor [0][0]};

 n = mA->rows;
                mMinor.rows=(n-1);
                mMinor.cols=(n-1)*TWOCOL;

  tci = 0;
  for (i = 0 ; i < mA->rows ; i++)
   {
    if(i != ci){

    tcj = 0;
    for ( j = 0; j < mA->cols ; j++,j++)
     {
      if(j != cj * TWOCOL)
      {
       *(mMinor.pblock+tci *mMinor.cols+tcj   ) = *(mA->pblock+i *mA->cols+j  );
       *(mMinor.pblock+tci *mMinor.cols+ tcj+1) = *(mA->pblock+i *mA->cols+j+1);

       tcj++;
       tcj++;
      }
     }
    tci++; }
   }

          f = detF(&mMinor);
    f.numer = pow(-1,(ci+1+cj+1))* f.numer;

  return(f);
}


/* --------------------------------- FUNCTION ------------------------------  */
/* Do    :                                                                    */
/*                                                                            */
/* Call  :                                                                    */
/* Debug :                                                                    */
/* -------------------------------------------------------------------------- */
void    mcofactorF(
pmatrix mA,
pmatrix mCofactor)
{
     int i;
     int j;
fraction f;

  if (mA->rows != mCofactor->rows || mA-> cols != mCofactor->cols)
    {
     printf("\n mcofactor() error - matrices different sizes");
     printf("\n Press return to continue");
     getchar();
     exit(1);
    }

 for (i = 0 ; i < mA->rows ; i++)
  {
   for ( j = 0 ; j < mA->cols ; j++, j++)
    {
               f =  cofactorF(mA,i, j/TWOCOL);

     *(mCofactor->pblock+i *mCofactor->cols+j  ) = f.numer;
     *(mCofactor->pblock+i *mCofactor->cols+j+1) = f.denom;
    }
  }
}


/* --------------------------------- FUNCTION ------------------------------  */
/* Do    :                                                                    */
/*                                                                            */
/* Call  :                                                                    */
/* Debug :                                                                    */
/* -------------------------------------------------------------------------- */
void    adjointF(
pmatrix mCofactor,
pmatrix mAdjoint)
{
  if (mCofactor->rows != mAdjoint->rows || mCofactor-> cols != mAdjoint->cols)
    {
     printf("\n adjoint() error - matrices different sizes");
     printf("\n Press return to continue");
     getchar();
     exit(1);
    }

 transposemF(mCofactor,mAdjoint);
}


/* --------------------------------- FUNCTION ------------------------------  */
/* Do    :                                                                    */
/*                                                                            */
/* Call  :                                                                    */
/* Debug :                                                                    */
/* -------------------------------------------------------------------------- */
void inverseF(
pmatrix  mA,
pmatrix  mInverse)
{
int      row;
int      n;
fraction f;

double pCofact[MXR][MXC*TWOCOL];matrix mCofact={MXR,MXC*TWOCOL,&pCofact[0][0]};

 n = mA->rows;
               mCofact.rows=n       ;
               mCofact.cols=n*TWOCOL;

     mcofactorF(mA,&mCofact);
       adjointF(   &mCofact,mInverse);

      f = detF(mA);
      f = invF(f);
    for ( row = 0; row < mA->rows ; row++)
     {
        mulrowF(mInverse,row,f);
      frowminiF(mInverse,row  );                        /* a) fraction mini   */
     }
}

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.