Aller au contenu

Mathc matrices/c09a02

Un livre de Wikilivres.


Étude du code


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


inv02.c
/* ------------------------------------ */
/*  Save as :   inv02.c                 */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
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);

clrscrn();
printf("/* --------- DEBUG 1 ---------- */\n");
       eye_mR(ID);
/* --------------------------- */
printf(" ID :     eye_mR(ID);");
p_mR(ID,S3,P0,C6);
stop();

clrscrn();
printf("   A :");
p_mR(A,S3,P0,C6);
printf("  ID :");
p_mR(ID,S3,P0,C6);
printf("  AID :");
p_mR(AID,S3,P0,C6);
printf("/* --------- DEBUG 2 ---------- */\n");
  c_A_b_Ab_mR(A,ID,AID);
/* --------------------------- */
printf(" AID :    c_A_b_Ab_mR(A,ID,AID);");
p_mR(AID,S3,P0,C10);  
stop();

clrscrn();  
printf("/* --------- DEBUG 3 ---------- */\n");
   invgj_pivot_mR(AID);
/* --------------------------- */
printf(" AID :     invgj_pivot_mR(AID);");
p_mR(AID,S6,P6,C6);  
stop();

clrscrn();
printf(" AID :   \n");
pall_mR(AID,S6,P6,C8);
printf("/* --------- DEBUG 4 ---------- */\n\n\n");
    sort_c_mR(AID);
/* --------------------------- */
printf(" AID :     sort_c_mR(AID);\n");
pall_mR(AID,S6,P6,C8); 
stop();

clrscrn();
printf(" AID :");
p_mR(AID,S6,P6,C6); 
printf("/* --------- DEBUG 5 ---------- */\n\n");
    sort_r_mR(AID);
/* --------------------------- */
printf(" AID :    sort_r_mR(AID);");
p_mR(AID,S6,P6,C6);  
stop();

clrscrn();
printf(" AID :  ");
p_mR(AID,S6,P6,C6);  
printf("/* --------- DEBUG 6 ---------- */\n");
   c_Inv_A_mR(AID,invA);
/* --------------------------- */
printf(" invA :    c_Inv_A_mR(AID,invA);");
p_mR(invA,S6,P6,C6); 
stop(); 
clrscrn(); 

  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(C3);

} while(stop_w());

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


  • Créer la matrice Ab (AID) avec r lignes, Ac colonnes (A) et bc colonnes (ID).
  • Construire la matrice identité (ID).
  • Copier la matrice A (A) et b (ID) dans Ab (AID).
  • Inverser la matrice avec la méthode de gaussjordan.
  • Trier les colonnes.
  • Trier les lignes.
  • Copier la matrice inverse dans la matrice invA.


Dans DEBUG 4 on utilise la fonction pall_mR(); pour afficher la colonne zéro et voir l'index des colonnes.


Exemple de sortie écran :
 ------------------------------------ 
 A :
-57 +34 +66 
-61 +42 -21 
-75 -95 -35 

 Press return to continue. 



/* --------- DEBUG 1 ---------- */
 ID :     eye_mR(ID);
 +1  +0  +0 
 +0  +1  +0 
 +0  +0  +1 

 Press return to continue. 



   A :
-57 +34 +66 
-61 +42 -21 
-75 -95 -35 

  ID :
 +1  +0  +0 
 +0  +1  +0 
 +0  +0  +1 

  AID :
 +0  +0  +0  +0  +0  +0 
 +0  +0  +0  +0  +0  +0 
 +0  +0  +0  +0  +0  +0 

/* --------- DEBUG 2 ---------- */
 AID :    c_A_b_Ab_mR(A,ID,AID);
-57 +34 +66  +1  +0  +0 
-61 +42 -21  +0  +1  +0 
-75 -95 -35  +0  +0  +1 

 Press return to continue. 



/* --------- DEBUG 3 ---------- */
 AID :     invgj_pivot_mR(AID);
+1.000000 +0.000000 +0.000000 +0.009033 -0.000728 -0.006793 
-0.000000 +1.000000 +0.000000 -0.006607 -0.004507 -0.004534 
+0.000000 +0.000000 +1.000000 -0.010360 +0.011634 -0.000416 

 Press return to continue. 



 AID :   
+4.000000 +2.000000 +1.000000 +3.000000 +5.000000 +4.000000 +6.000000  <- index colonnes

+7.000000 +1.000000 +0.000000 +0.000000 +0.009033 -0.000728 -0.006793 
+4.000000 -0.000000 +1.000000 +0.000000 -0.006607 -0.004507 -0.004534 
+0.000000 +0.000000 +0.000000 +1.000000 -0.010360 +0.011634 -0.000416 

/* --------- DEBUG 4 ---------- */

 AID :     sort_c_mR(AID);
+4.000000 +1.000000 +2.000000 +3.000000 +4.000000 +5.000000 +6.000000 

+7.000000 +0.000000 +1.000000 +0.000000 -0.000728 +0.009033 -0.006793 
+4.000000 +1.000000 -0.000000 +0.000000 -0.004507 -0.006607 -0.004534 
+0.000000 +0.000000 +0.000000 +1.000000 +0.011634 -0.010360 -0.000416 

 Press return to continue. 




 AID :
+0.000000 +1.000000 +0.000000 -0.000728 +0.009033 -0.006793 
+1.000000 -0.000000 +0.000000 -0.004507 -0.006607 -0.004534 
+0.000000 +0.000000 +1.000000 +0.011634 -0.010360 -0.000416 

/* --------- DEBUG 5 ---------- */

 AID :    sort_r_mR(AID);
+1.000000 -0.000000 +0.000000 -0.004507 -0.006607 -0.004534 
+0.000000 +1.000000 +0.000000 -0.000728 +0.009033 -0.006793 
+0.000000 +0.000000 +1.000000 +0.011634 -0.010360 -0.000416 

 Press return to continue. 



 AID :  
+1.000000 -0.000000 +0.000000 -0.004507 -0.006607 -0.004534 
+0.000000 +1.000000 +0.000000 -0.000728 +0.009033 -0.006793 
+0.000000 +0.000000 +1.000000 +0.011634 -0.010360 -0.000416 

/* --------- DEBUG 6 ---------- */
 invA :    c_Inv_A_mR(AID,invA);
-0.004507 -0.006607 -0.004534 
-0.000728 +0.009033 -0.006793 
+0.011634 -0.010360 -0.000416 

 Press return to continue. 



 Copy/Past into the octave window.

format short e
 A=[
-57,+34,+66;
-61,+42,-21;
-75,-95,-35]

 inv(A)
 -4.5068e-03  -6.6074e-03  -4.5341e-03 
 -7.2837e-04  +9.0331e-03  -6.7934e-03 
 +1.1634e-02  -1.0360e-02  -4.1621e-04 

 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