Linear Algebra and the C Language/a09w


Code study: gj_TP_mR();

  • The function create the system A|ID
  • This function calls invgj_pivot_mR(); which use the total pivoting algorithm.
  • Then the function sorts the columns.
  • Then the function sorts the rows.
  • Finally the function copy the inverse into the matrix InvA.


/* ------------------------------------ */
/* ------------------------------------ */
double **invgj_pivot_mR(
double **Ab
)
{
double pivot = 1.;

int r= R1;

    while( pivot &&
          (r<Ab[R_SIZE  ][C0])
         )
       {
        pivot = pivotbestAId_mR(Ab,r);
        
        if(pivot>ERROR_E) 
                 zero_under_pivot_gj1Ab_mR(Ab,r);
        r++;
       }

    while( (r>R1) )
       {
		 r--;
         zero_above_pivot_gj1Ab_mR(Ab,r);
	    }
        
return(Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **invgj_mR(
double **A,
double **invA
)
{
double **ID = i_RC_mR(A[R_SIZE][C0],A[C_SIZE][C0]);
double **AID;

int r = A[R_SIZE][C0];

  r--;

  AID = i_Abr_Ac_bc_mR(r,r,r);

       eye_mR(ID);
  c_A_b_Ab_mR(A,ID,AID);
   invgj_pivot_mR(AID);
    sort_c_mR(AID);
    sort_r_mR(AID);
   c_Inv_A_mR(AID,invA);

  f_mR(AID);
  f_mR(ID);

return(invA);
}
/* ------------------------------------ */
/* ------------------------------------ */