Mathc matrices/c09a09

Un livre de Wikilivres.


Étude du code


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


inv09.c
/* ------------------------------------ */
/*  Save as :   inv09.c                 */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
double **xx_sort_c_mR(
double **Ab
)
{
double **T = i_RC_mR(Ab[R_SIZE][C0],Ab[C_SIZE][C0]);
int c;

  for(c=C1; c<Ab[C_SIZE][C0]; c++)
  {
clrscrn(); 
printf("/* --------- DEBUG 1 ---------- */\n\n");	           
printf(" Copy  C[%d] of Ab into C[%.0f] of T\n",c,Ab[R0][c]);
pall_mR(Ab,S8,P4,C8);

           c_c_withR0_mR(  Ab,        c,
                            T, Ab[R0][c]);
                            
printf(" T[R0][%.0f]\n",Ab[R0][c]);
pall_mR(T,S8,P4,C8);
stop();
clrscrn(); 
/* --------- DEBUG 1 ---------- */
   }
   
 c_withR0_mR(T,Ab);
  
 f_mR(T);
 
 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);
    xx_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();

  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)\n");
  pE_mR(Inv,S12,P4,C6);

  printf(" A * inv(A)\n");
  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(C3);

} while(stop_w());

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


Nous utilisons la fonction pall_mR(); au lieu de p_mR(); pour voir l'index des colonnes.


Exemple de sortie écran :
 ------------------------------------ 


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

 Copy  C[1] of Ab into C[2] of T
 +4.0000  +2.0000  +1.0000  +3.0000  +5.0000  +4.0000  +6.0000 

 +7.0000  +1.0000  +0.0000  +0.0000  -0.0155  +0.0316  +0.0013 
 +4.0000  +0.0000  +1.0000  +0.0000  -0.0017  -0.0132  +0.0049 
 +0.0000  +0.0000  +0.0000  +1.0000  -0.0221  +0.0770  +0.0165 

 T[R0][2]
 +4.0000  +1.0000  +2.0000  +3.0000  +4.0000  +5.0000  +6.0000 

 +7.0000  +0.0000  +1.0000  +0.0000  +0.0000  +0.0000  +0.0000 
 +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000 
 +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000 

 Press return to continue. 


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

 Copy  C[2] of Ab into C[1] of T
 +4.0000  +2.0000  +1.0000  +3.0000  +5.0000  +4.0000  +6.0000 

 +7.0000  +1.0000  +0.0000  +0.0000  -0.0155  +0.0316  +0.0013 
 +4.0000  +0.0000  +1.0000  +0.0000  -0.0017  -0.0132  +0.0049 
 +0.0000  +0.0000  +0.0000  +1.0000  -0.0221  +0.0770  +0.0165 

 T[R0][1]
 +4.0000  +1.0000  +2.0000  +3.0000  +4.0000  +5.0000  +6.0000 

 +7.0000  +0.0000  +1.0000  +0.0000  +0.0000  +0.0000  +0.0000 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000 
 +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000 

 Press return to continue. 


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

 Copy  C[3] of Ab into C[3] of T
 +4.0000  +2.0000  +1.0000  +3.0000  +5.0000  +4.0000  +6.0000 

 +7.0000  +1.0000  +0.0000  +0.0000  -0.0155  +0.0316  +0.0013 
 +4.0000  +0.0000  +1.0000  +0.0000  -0.0017  -0.0132  +0.0049 
 +0.0000  +0.0000  +0.0000  +1.0000  -0.0221  +0.0770  +0.0165 

 T[R0][3]
 +4.0000  +1.0000  +2.0000  +3.0000  +4.0000  +5.0000  +6.0000 

 +7.0000  +0.0000  +1.0000  +0.0000  +0.0000  +0.0000  +0.0000 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0000  +0.0000  +0.0000 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0000  +0.0000  +0.0000 

 Press return to continue. 


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

 Copy  C[4] of Ab into C[5] of T
 +4.0000  +2.0000  +1.0000  +3.0000  +5.0000  +4.0000  +6.0000 

 +7.0000  +1.0000  +0.0000  +0.0000  -0.0155  +0.0316  +0.0013 
 +4.0000  +0.0000  +1.0000  +0.0000  -0.0017  -0.0132  +0.0049 
 +0.0000  +0.0000  +0.0000  +1.0000  -0.0221  +0.0770  +0.0165 

 T[R0][5]
 +4.0000  +1.0000  +2.0000  +3.0000  +4.0000  +5.0000  +6.0000 

 +7.0000  +0.0000  +1.0000  +0.0000  +0.0000  -0.0155  +0.0000 
 +0.0000  +1.0000  +0.0000  +0.0000  +0.0000  -0.0017  +0.0000 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0000  -0.0221  +0.0000 

 Press return to continue. 



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

 Copy  C[5] of Ab into C[4] of T
 +4.0000  +2.0000  +1.0000  +3.0000  +5.0000  +4.0000  +6.0000 

 +7.0000  +1.0000  +0.0000  +0.0000  -0.0155  +0.0316  +0.0013 
 +4.0000  +0.0000  +1.0000  +0.0000  -0.0017  -0.0132  +0.0049 
 +0.0000  +0.0000  +0.0000  +1.0000  -0.0221  +0.0770  +0.0165 

 T[R0][4]
 +4.0000  +1.0000  +2.0000  +3.0000  +4.0000  +5.0000  +6.0000 

 +7.0000  +0.0000  +1.0000  +0.0000  +0.0316  -0.0155  +0.0000 
 +0.0000  +1.0000  +0.0000  +0.0000  -0.0132  -0.0017  +0.0000 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0770  -0.0221  +0.0000 

 Press return to continue. 



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

 Copy  C[6] of Ab into C[6] of T
 +4.0000  +2.0000  +1.0000  +3.0000  +5.0000  +4.0000  +6.0000 

 +7.0000  +1.0000  +0.0000  +0.0000  -0.0155  +0.0316  +0.0013 
 +4.0000  +0.0000  +1.0000  +0.0000  -0.0017  -0.0132  +0.0049 
 +0.0000  +0.0000  +0.0000  +1.0000  -0.0221  +0.0770  +0.0165 

 T[R0][6]
 +4.0000  +1.0000  +2.0000  +3.0000  +4.0000  +5.0000  +6.0000 

 +7.0000  +0.0000  +1.0000  +0.0000  +0.0316  -0.0155  +0.0013 
 +0.0000  +1.0000  +0.0000  +0.0000  -0.0132  -0.0017  +0.0049 
 +0.0000  +0.0000  +0.0000  +1.0000  +0.0770  -0.0221  +0.0165 

 Press return to continue. 


 Copy/Past into the octave window.

format short e
 A=[
-37,-13,+12;
-69,-97,+28;
+80,-69,+42]

 inv(A)
 -1.3164e-02  -1.7331e-03  +4.9167e-03 
 +3.1577e-02  -1.5451e-02  +1.2783e-03 
 +7.6952e-02  -2.2082e-02  +1.6545e-02 

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


 Press return to continue
 Press X      to stop