Mathc matrices/Fichiers c : add r2

Un livre de Wikilivres.


Application

Installer et compiler ce fichier dans votre répertoire de travail.

addr.c
/* ------------------------------------ */
/*  Save as : addr.c                    */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
int main(void)
{
double a[R3*C3] ={  1,   2,   3,
                    2,   2,   2,
                    3,   3,   3 };
                     
double **A = ca_A_mR(a, i_mR(R3,C3));

double s;

int r1;
int r2;

/* ------------------------------------ */
 clrscrn();
 
 printf(" A :");
 p_mR(A,S5,P0,C6);
 
 s = -2.;  
 
 r1 = R1;  
 r2 = R2;
 
 printf(" Multiply the R%d by %+.0f,   \n",r1,s);
 printf(" then add the R%d and the R%d \n",r1,r2);
 printf(" put the result into the R%d  \n\n",r2);
 
 printf(" A :");
 p_mR(addR_mR(A,s,r1,r2),S5,P0,C6);
 
 getchar();

/* ------------------------------------ */
 clrscrn();
 
 printf(" A :");
 p_mR(A,S5,P0,C6);
 
 s = -3.;  
 
 r1 = R1;  
 r2 = R3;
 
 printf(" Multiply the R%d by %+.0f,   \n",r1,s);
 printf(" then add the R%d and the R%d \n",r1,r2);
 printf(" put the result into the R%d  \n\n",r2);
 
 printf(" A :");
 p_mR(addR_mR(A,s,r1,r2),S5,P0,C6);
 
 stop();
 
 f_mR(A);
 
 return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


La fonction addR_mR(); multiplie la ligne r1 par un scalaire sans la modifier et l'ajoute à la ligne r2 et remplace la ligne r2 par le résultat de cette opération .

Cette opération permet de poser des zéros sous le pivot. Voir le résultat dans la dernière matrice.


Exemple de sortie écran :

 A :
   +1    +2    +3 
   +2    +2    +2 
   +3    +3    +3 

 Multiply the R1 by -2,   
 then add the R1 and the R2 
 put the result into the R2  

 A :
   +1    +2    +3 
   +0    -2    -4 
   +3    +3    +3 

------------------------

 A :
   +1    +2    +3 
   +0    -2    -4 
   +3    +3    +3 

 Multiply the R1 by -3,   
 then add the R1 and the R3 
 put the result into the R3  

 A :
   +1    +2    +3 
   +0    -2    -4 
   +0    -3    -6 

 Press return to continue.