Mathc matrices/Fichiers c : add c

Un livre de Wikilivres.


Application

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

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

double **A = ca_A_mR(a,i_mR(R3,C3));

double   s = 0.;
int     c1 = C0;
int     c2 = C0;

/* ------------------------------------ */
 clrscrn();
 
 s  = -2.;
 
 c1 = C1;
 c2 = C2;
 
 printf(" A :");
 p_mR(A,S5,P0,C6);
 
 printf(" Multiply the C%d by %+.0f,   \n",c1,s);
 printf(" then add the C%d and the C%d \n",c1,c2);
 printf(" put the result into the C%d  \n\n",c2);
 printf(" A : \n");
 p_mR(addC_mR(A,s,c1,c2),S5,P0,C6);
 
 getchar();

/* ------------------------------------ */
 clrscrn();
 
 s  = -3.;
 
 c1 = C1;
 c2 = C3;
 
 printf(" A :");
 p_mR(A,S5,P0,C6);
 
 printf(" Multiply the C%d by %+.0f,   \n",c1,s);
 printf(" then add the C%d and the C%d \n",c1,c2);
 printf(" put the result into the C%d  \n\n",c2);
 printf(" A : \n");
 p_mR(addC_mR(A,s,c1,c2),S5,P0,C6);
 
 f_mR(A);

 stop();
 
 return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


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

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


Exemple de sortie écran :

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

 Multiply the C1 by -2,   
 then add the C1 and the C2 
 put the result into the C2  

 A : 

   +1    +0    +3 
   +2    -2    +3 
   +3    -4    +3 

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

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

 Multiply the C1 by -3,   
 then add the C1 and the C3 
 put the result into the C3  

 A : 

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

 Press return to continue.