Mathc complexes/Fichiers c :canImul

Un livre de Wikilivres.


Application


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

canImul.c
Vérification d'erreurs
/* ------------------------------------ */
/*  Save as :   canImul.c               */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
void xcanImul_mZ(
double **A,
double **B,
double **AB,
char function[],
char matrices[]
)
{
 if ( (((B[R_SIZE][C0]-C1)*C2) != (A[C_SIZE][C0]-C1))
                               ||
               ( A[R_SIZE][C0] != AB[R_SIZE][C0] )
                               ||
               ( B[C_SIZE][C0] != AB[C_SIZE][C0] )   )
    {
     printf("\n Error : %s\n",function);
     printf("\n Verify the size of the matrices%s \n",matrices);
     printf("\n Press return to continue.\n");
     fflush(stdout);
     getchar();
     exit(EXIT_FAILURE);
    }
}
/* ------------------------------------ */
int main(void)
{  
double **A     = i_mZ(R2,R4);
double **B     = i_mZ(R4,R3);
double **AB    = i_mZ(R4,R3);

  clrscrn();
  
  printf(" A[R%d,C%d] : \n",rsize_mZ(A),csize_mZ(A));
  p_mZ(A, 5,0, 4,0, C6);

  printf(" B[R%d,C%d] : \n",rsize_mZ(B),csize_mZ(B));
  p_mZ(B, 5,0, 4,0, C6);

  printf(" AB[R%d,C%d] : \n",rsize_mZ(AB),csize_mZ(AB));
  p_mZ(AB, 5,0, 4,0, C6);
   
  xcanImul_mZ(A,B,AB,"mul_mZ();","(A or B or AB)");
  
  f_mZ(A);
  f_mZ(B);
  f_mZ(AB);
        
  return 0;
}


La fonction canImul_mZ(); existant déjà dans la librairie je l'ai ici renommé xcanImul_mZ();


Exemple de sortie écran :

 A[R2,C4] : 

   +0  +0i    +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i    +0  +0i 

 B[R4,C3] : 

   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 

 AB[R4,C3] : 

   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 


 Error : mul_mZ();

 Verify the size of the matrices(A or B or AB) 

 Press return to continue.


Les matrices n'étant pas de taille compatible, la fonction d'erreur arrête le programme.


Vous pouvez essayer un autre exemple en changeant les valeurs ci-dessous :

double **A     = i_mZ(R2,R4);
double **B     = i_mZ(R4,R3);
double **AB    = i_mZ(R2,R3);


 A[R2,C4] : 

   +0  +0i    +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i    +0  +0i 

 B[R4,C3] : 

   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 

 AB[R2,C3] : 

   +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i 



------------------
(program exited with code: 0)
Press return to continue


Cette fois-ci la fonction d'erreur n'arrête plus le programme.