Mathc complexes/Fichiers c :canItran

Un livre de Wikilivres.


Application


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

canItran.c
Vérification d'erreurs
/* ------------------------------------ */
/*  Save as :   canItran.c              */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
void xcanItranspose_mZ(
double **A,
double **A_t,
char function[],
char matrices[]
)
{
  if (
       ((A[R_SIZE][C0]-C1)*C2) != (A_t[C_SIZE][C0]-C1)
                               ||
     ((A_t[R_SIZE][C0]-C1)*C2) !=  (A[C_SIZE][C0]-C1)   )
    {
     printf("\n Error : %s\n",function);
     printf("\n Verify the sizes 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(R4,R4);
double **A_t   = i_mZ(R5,R4);

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

  printf(" A_t[R%d,C%d] : \n",rsize_mZ(A_t),csize_mZ(A_t));
  p_mZ(A_t, 5,0, 4,0, C6);
   
  xcanItranspose_mZ(A,A_t,"My function","(A or A_t)");
  
  f_mZ(A);
  f_mZ(A_t);
        
  return 0;
}


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


Exemple de sortie écran :

 A[R4,C4] : 

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

 A_t[R5,C4] : 

   +0  +0i    +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i    +0  +0i 
   +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 : My function

 Verify the sizes of the matrices(A or A_t) 

 Press return to continu


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(R4,R5);
double **A_t   = i_mZ(R5,R4);


 A[R4,C5] : 

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

 A_t[R5,C4] : 

   +0  +0i    +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +0  +0i    +0  +0i 
   +0  +0i    +0  +0i    +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.