Linear Algebra and the C Language/a0kp


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as:    c00e.c                 */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **X_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>R2) )
       {
		 r--; 
		 
  clrscrn();     
  printf("/* --------- DEBUG 1 ---------- */\n");	       
  printf(" AID:");
  p_mR(Ab, S8,P4,C8);
  
         zero_above_pivot_gj1Ab_mR(Ab,r);

        printf(" pivot[%d][[%d]:             \n\n"
               " zero_above_pivot_gj1Ab_mR();\n\n AID:"
               ,r,r);         
  p_mR(Ab, S8,P4,C8);
  stop();
	    }
        
 clrscrn();
 printf(" zero_above_pivot_gj1Ab_mR();\n\n"
        " AID:");
 p_mR(Ab, S8,P4,C8); 

        
return(Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **X_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);
   X_invgj_pivot_mR(AID);
/*        sort_c_mR(AID);      */
/*      v sort_r_mR(AID);      */
/*       c_Inv_A_mR(AID,invA); */

  f_mR(AID);
  f_mR(ID);

return(invA);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r)
{
double **A    = rE_mR( i_mR(r,r), 999.,1E-3);
double **InvA =        i_mR(r,r);

  clrscrn();
  
  printf(" A:");
  p_mR(A, S3,P4,C6);
  stop();  
  
  X_invgj_mR(A,InvA);
 
  f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
  
do
{
   fun(C4);

} while(stop_w());

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */

Screen output example:

                                                                                       
 A:
-0.9340 +0.5210 -0.5950 +0.2210 
+0.1630 -0.7800 -0.3630 +0.3260 
-0.8320 +0.3540 -0.7680 +0.5850 
-0.7000 -0.6970 +0.3180 +0.4540 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */
 AID:
 +1.0000  -0.5578  +0.6370  -0.2366  -1.0707  -0.0000  -0.0000  -0.0000 
 +0.0000  +1.0000  -0.7025  -0.2652  +0.6892  -0.0000  -0.0000  -0.9196 
 -0.0000  -0.0000  +1.0000  -0.1912  -0.6829  -1.0516  -0.0000  +0.6664 
 -0.0000  +0.0000  +0.0000  +1.0000  -3.4499  -1.1104  +3.3485  +0.3646 

 pivot[4][[4]:             

 zero_above_pivot_gj1Ab_mR();

 AID:
 +1.0000  -0.5578  +0.6370  +0.0000  -1.8870  -0.2627  +0.7923  +0.0863 
 -0.0000  +1.0000  -0.7025  +0.0000  -0.2256  -0.2944  +0.8879  -0.8229 
 -0.0000  +0.0000  +1.0000  +0.0000  -1.3427  -1.2640  +0.6403  +0.7361 
 -0.0000  +0.0000  +0.0000  +1.0000  -3.4499  -1.1104  +3.3485  +0.3646 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */
 AID:
 +1.0000  -0.5578  +0.6370  +0.0000  -1.8870  -0.2627  +0.7923  +0.0863 
 -0.0000  +1.0000  -0.7025  +0.0000  -0.2256  -0.2944  +0.8879  -0.8229 
 -0.0000  +0.0000  +1.0000  +0.0000  -1.3427  -1.2640  +0.6403  +0.7361 
 -0.0000  +0.0000  +0.0000  +1.0000  -3.4499  -1.1104  +3.3485  +0.3646 

 pivot[3][[3]:             

 zero_above_pivot_gj1Ab_mR();

 AID:
 +1.0000  -0.5578  +0.0000  +0.0000  -1.0316  +0.5425  +0.3844  -0.3827 
 -0.0000  +1.0000  +0.0000  +0.0000  -1.1688  -1.1824  +1.3378  -0.3058 
 -0.0000  +0.0000  +1.0000  +0.0000  -1.3427  -1.2640  +0.6403  +0.7361 
 -0.0000  +0.0000  +0.0000  +1.0000  -3.4499  -1.1104  +3.3485  +0.3646 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */
 AID:
 +1.0000  -0.5578  +0.0000  +0.0000  -1.0316  +0.5425  +0.3844  -0.3827 
 -0.0000  +1.0000  +0.0000  +0.0000  -1.1688  -1.1824  +1.3378  -0.3058 
 -0.0000  +0.0000  +1.0000  +0.0000  -1.3427  -1.2640  +0.6403  +0.7361 
 -0.0000  +0.0000  +0.0000  +1.0000  -3.4499  -1.1104  +3.3485  +0.3646 

 pivot[2][[2]:             

 zero_above_pivot_gj1Ab_mR();

 AID:
 +1.0000  +0.0000  +0.0000  +0.0000  -1.6836  -0.1171  +1.1306  -0.5532 
 -0.0000  +1.0000  +0.0000  +0.0000  -1.1688  -1.1824  +1.3378  -0.3058 
 -0.0000  +0.0000  +1.0000  +0.0000  -1.3427  -1.2640  +0.6403  +0.7361 
 -0.0000  +0.0000  +0.0000  +1.0000  -3.4499  -1.1104  +3.3485  +0.3646 

 Press return to continue. 


 zero_above_pivot_gj1Ab_mR();

 AID:
 +1.0000  +0.0000  +0.0000  +0.0000  -1.6836  -0.1171  +1.1306  -0.5532 
 -0.0000  +1.0000  +0.0000  +0.0000  -1.1688  -1.1824  +1.3378  -0.3058 
 -0.0000  +0.0000  +1.0000  +0.0000  -1.3427  -1.2640  +0.6403  +0.7361 
 -0.0000  +0.0000  +0.0000  +1.0000  -3.4499  -1.1104  +3.3485  +0.3646 


 Press   return to continue
 Press X return to stop