Étude du code


Installer et compiler ces fichiers dans votre répertoire de travail.


inv11.c
/* ------------------------------------ */
/*  Save as :   inv11.c                 */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **xx_sort_r_mR(
double **Ab
)
{
double pivot;
int c;
int r;
int r_pivot = R1;

clrscrn();            
printf(" Ab");
pE_mR(Ab,S12,P4,C6);
stop();
clrscrn(); 

    for ( c=C1; c<Ab[C_SIZE_A][C0]; c++)
      {
              r = r_pivot;
          pivot = 0.;
          
      while( (pivot<ERROR_E) && r<Ab[R_SIZE][C0] )
         {
          pivot = fabs( Ab[r][c] );
clrscrn();     
printf("/* --------- DEBUG 1 ---------- */\n\n");       
printf(" Ab : pivot[%d][%d] = %f  ",r,c,pivot);
p_mR(Ab,S8,P4,C8);

          if(pivot>ERROR_E) 
          {
            swapR_mR(Ab, r, r_pivot);
            r_pivot++;
          }
printf(" Ab");
p_mR(Ab,S8,P4,C8);
stop();
clrscrn();                            
/* --------- DEBUG 1 ---------- */

          r++;
         }
       }
       
 return(Ab);
}
/* ------------------------------------ */
/* ------------------------------------ */
double **XX_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);
    xx_sort_r_mR(AID);
   c_Inv_A_mR(AID,invA);

  f_mR(AID);
  f_mR(ID);

return(invA);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r)
{
double **A   = r_mR( i_mR(r,r), 99.);
double **Inv =       i_mR(r,r);
double **AInv =      i_mR(r,r);

  clrscrn();

  XX_invgj_mR(A,Inv);
  
  printf(" Copy/Past into the octave window.\n\n");
  printf("format short e\n");
  p_Octave_mR(A,"A",P0);
   
  printf(" inv(A)");
  pE_mR(Inv,S12,P4,C6);

  printf(" A * inv(A)");
  mul_mR(A,Inv,AInv);
  p_mR(AInv,S12,P4,C6);
  
  f_mR(AInv);  
  f_mR(Inv);
  f_mR(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

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

} while(stop_w());

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


On commence par regarder le premier pivot (R1xC1), si il est nulle on descend dans la colonne pour trouver un pivot non nul. Lorsque le pivot non nul est trouver on échange la ligne  avec la ligne du pivot. Puis on passe à la colonne suivante (R2xC2).


Exemple de sortie écran :
 ------------------------------------ 
 Ab
 +0.0000e+00  +0.0000e+00  +0.0000e+00  +1.0000e+00  +4.0500e-03  -8.0479e-04 
 +1.0000e+00  +0.0000e+00  +0.0000e+00  +0.0000e+00  -5.6074e-03  +6.9059e-03 
 +0.0000e+00  +1.0000e+00  +0.0000e+00  +0.0000e+00  +1.0105e-02  +4.9401e-03 
 -0.0000e+00  -0.0000e+00  +1.0000e+00  -0.0000e+00  +3.5346e-03  -6.3411e-03 

 -1.4045e-02  -1.7865e-03 
 +2.3002e-03  +4.6525e-03 
 +7.0962e-03  +1.0533e-02 
 -1.2066e-02  +6.2204e-03 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */

 Ab : pivot[1][1] = 0.000000  
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Ab
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */

 Ab : pivot[2][1] = 1.000000  
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Ab
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */

 Ab : pivot[2][2] = 0.000000  
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Ab
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */

 Ab : pivot[3][2] = 1.000000  
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Ab
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */

 Ab : pivot[3][3] = 0.000000  
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Ab
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */

 Ab : pivot[4][3] = 1.000000  
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 

 Ab
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */

 Ab : pivot[4][4] = 1.000000  
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 

 Ab
 +1.0000  +0.0000  +0.0000  +0.0000  -0.0056  +0.0069  +0.0023  +0.0047 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0101  +0.0049  +0.0071  +0.0105 
 -0.0000  -0.0000  +1.0000  -0.0000  +0.0035  -0.0063  -0.0121  +0.0062 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0041  -0.0008  -0.0140  -0.0018 

 Press return to continue. 


 Copy/Past into the octave window.

format short e
 A=[
-65,+56,-33,+46;
+68,+28,-73,+88;
-29,+12,-15,-57;
+50,+20,+76,-47]

 inv(A)
 -5.6074e-03  +6.9059e-03  +2.3002e-03  +4.6525e-03 
 +1.0105e-02  +4.9401e-03  +7.0962e-03  +1.0533e-02 
 +3.5346e-03  -6.3411e-03  -1.2066e-02  +6.2204e-03 
 +4.0500e-03  -8.0479e-04  -1.4045e-02  -1.7865e-03 

 A * inv(A)
     +1.0000      -0.0000      +0.0000      +0.0000 
     +0.0000      +1.0000      +0.0000      +0.0000 
     +0.0000      +0.0000      +1.0000      -0.0000 
     +0.0000      +0.0000      +0.0000      +1.0000 


 Press return to continue
 Press X      to stop