Aller au contenu

Mathc matrices/c09a04

Un livre de Wikilivres.


Étude du code


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


inv04.c
/* ------------------------------------ */
/*  Save as :   inv04.c                 */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
/* ------------------------------------ */
double **XX_invgj_pivot_mR(
double **Ab
)
{
double pivot = 1.;

int r= R1;

    while( pivot &&
          (r<Ab[R_SIZE  ][C0])
         )
       {
		   
        clrscrn();	
printf("/* --------- DEBUG 1 ---------- */\n");	   
		printf(" inv(A)\n");
        p_mR(Ab,S8,P4,C8);
        pivot = pivotbestAId_mR(Ab,r);
        printf(" pivot[%d][[%d] = %f\n",r,r,pivot);
        printf(" inv(A)\n");
        p_mR(Ab,S8,P4,C8);
        stop();

       
        if(pivot>ERROR_E) 
                 zero_under_pivot_gj1Ab_mR(Ab,r);
        r++;
       }
		      
clrscrn();
printf(" inv(A)\n");
p_mR(Ab,S8,P4,C8); 
stop();
clrscrn();
/* --------------------------- */ 

    while( (r>R1) )
       {
		 r--;
         zero_below_pivot_gj1Ab_mR(Ab,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);
   XX_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);
}
/* ------------------------------------ */
/* ------------------------------------ */
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();
  
  printf(" A :");
  p_mR(A,S3,P0,C6);
  stop();  
  
  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;
}
/* ------------------------------------ */
/* ------------------------------------ */


Nous voyons dans cet exemple comment sont choisis les meilleurs pivots. Cela est toujours le plus grand coefficient en valeur absolue qui se trouve dans la matrice.


Exemple de sortie écran :
 ------------------------------------ 
 A :
-79 -61 +44 -59 
-51  -7 +26 +92 
-41 +96 -67  +2 
+10 +12 -57 +66 

 Press return to continue. 

/* --------- DEBUG 1 ---------- */
 inv(A)

-79.0000 -61.0000 +44.0000 -59.0000  +1.0000  +0.0000  +0.0000  +0.0000 
-51.0000  -7.0000 +26.0000 +92.0000  +0.0000  +1.0000  +0.0000  +0.0000 
-41.0000 +96.0000 -67.0000  +2.0000  +0.0000  +0.0000  +1.0000  +0.0000 
+10.0000 +12.0000 -57.0000 +66.0000  +0.0000  +0.0000  +0.0000  +1.0000 

 pivot[1][[1] = 96.000000
 inv(A)

+96.0000 -41.0000 -67.0000  +2.0000  +0.0000  +0.0000  +1.0000  +0.0000 
 -7.0000 -51.0000 +26.0000 +92.0000  +1.0000  +0.0000  +0.0000  +0.0000 
-61.0000 -79.0000 +44.0000 -59.0000  +0.0000  +1.0000  +0.0000  +0.0000 
+12.0000 +10.0000 -57.0000 +66.0000  +0.0000  +0.0000  +0.0000  +1.0000 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */
 inv(A)

 +1.0000  -0.4271  -0.6979  +0.0208  +0.0000  +0.0000  +0.0104  +0.0000 
 +0.0000 -53.9896 +21.1146 +92.1458  +1.0000  +0.0000  +0.0729  +0.0000 
 +0.0000 -105.0521  +1.4271 -57.7292  +0.0000  +1.0000  +0.6354  +0.0000 
 +0.0000 +15.1250 -48.6250 +65.7500  +0.0000  +0.0000  -0.1250  +1.0000 

 pivot[2][[2] = 105.052083
 inv(A)

 +1.0000  -0.4271  -0.6979  +0.0208  +0.0000  +0.0000  +0.0104  +0.0000 
 +0.0000 -105.0521  +1.4271 -57.7292  +0.0000  +1.0000  +0.6354  +0.0000 
 +0.0000 -53.9896 +21.1146 +92.1458  +1.0000  +0.0000  +0.0729  +0.0000 
 +0.0000 +15.1250 -48.6250 +65.7500  +0.0000  +0.0000  -0.1250  +1.0000 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */
 inv(A)

 +1.0000  -0.4271  -0.6979  +0.0208  +0.0000  +0.0000  +0.0104  +0.0000 
 -0.0000  +1.0000  -0.0136  +0.5495  -0.0000  -0.0095  -0.0060  -0.0000 
 +0.0000  +0.0000 +20.3812 +121.8147  +1.0000  -0.5139  -0.2536  +0.0000 
 +0.0000  +0.0000 -48.4195 +57.4384  +0.0000  +0.1440  -0.0335  +1.0000 

 pivot[3][[3] = 121.814675
 inv(A)

 +1.0000  -0.4271  +0.0208  -0.6979  +0.0000  +0.0000  +0.0000  +0.0104 
 -0.0000  +1.0000  +0.5495  -0.0136  -0.0000  -0.0095  -0.0000  -0.0060 
 +0.0000  +0.0000 +121.8147 +20.3812  +1.0000  -0.5139  +0.0000  -0.2536 
 +0.0000  +0.0000 +57.4384 -48.4195  +0.0000  +0.1440  +1.0000  -0.0335 

 Press return to continue. 


/* --------- DEBUG 1 ---------- */
 inv(A)

 +1.0000  -0.4271  +0.0208  -0.6979  +0.0000  +0.0000  +0.0000  +0.0104 
 -0.0000  +1.0000  +0.5495  -0.0136  -0.0000  -0.0095  -0.0000  -0.0060 
 +0.0000  +0.0000  +1.0000  +0.1673  +0.0082  -0.0042  +0.0000  -0.0021 
 +0.0000  +0.0000  +0.0000 -58.0297  -0.4715  +0.3863  +1.0000  +0.0861 

 pivot[4][[4] = 58.029712
 inv(A)

 +1.0000  -0.4271  +0.0208  -0.6979  +0.0000  +0.0000  +0.0000  +0.0104 
 -0.0000  +1.0000  +0.5495  -0.0136  -0.0000  -0.0095  -0.0000  -0.0060 
 +0.0000  +0.0000  +1.0000  +0.1673  +0.0082  -0.0042  +0.0000  -0.0021 
 +0.0000  +0.0000  +0.0000 -58.0297  -0.4715  +0.3863  +1.0000  +0.0861 

 Press return to continue. 


 inv(A)

 +1.0000  -0.4271  +0.0208  -0.6979  +0.0000  +0.0000  +0.0000  +0.0104 
 -0.0000  +1.0000  +0.5495  -0.0136  -0.0000  -0.0095  -0.0000  -0.0060 
 +0.0000  +0.0000  +1.0000  +0.1673  +0.0082  -0.0042  +0.0000  -0.0021 
 -0.0000  -0.0000  -0.0000  +1.0000  +0.0081  -0.0067  -0.0172  -0.0015 

 Press return to continue. 


 Copy/Past into the octave window.

format short e
 A=[
-79,-61,+44,-59;
-51,-7,+26,+92;
-41,+96,-67,+2;
+10,+12,-57,+66]

 inv(A)
 -7.9031e-03  -3.6537e-03  -5.0609e-03  -1.8185e-03 
 -7.9567e-03  +3.9678e-03  +7.2581e-03  -1.2864e-02 
 -6.6570e-03  +8.1255e-03  -1.4834e-03  -1.7233e-02 
 -3.1052e-03  +6.8497e-03  -1.8340e-03  +2.8832e-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