Aller au contenu

Mathc complexes/Fichiers c : trace

Un livre de Wikilivres.


Application

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

trace.c
/* ------------------------------------ */
/*  Save as :  trace.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
nb_Z xtrace_Z(
double **A
)
{
nb_Z trace;
nb_Z z;

int    r,c;

  isquare_mZ(A,"trace_mZ();","(A)");

  trace = i_Z(0,0);

  for (   r=R1,c=C1; r<A[R_SIZE][C0]; r++,c+=C2)
        {
         z = i_Z(A[r][c],A[r][c+C1]);
         trace = add_Z(trace,z);
        }

  return(trace);
}
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int rc)
{
double **A   = r_mZ(i_mZ(rc,rc),9);

   clrscrn();

   printf("  A\n");
   p_mZ(A, S5,P0, S4,P0,C6);

   printf("\n\n\n Trace of the matrix A = ");
   p_Z(trace_Z(A), S5,P0, S4,P0);
   printf("\n\n\n");
    
  f_mZ(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
  
   do 
         fun(rp_I(RC5));
        
    while(stop_w());

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
La fonction trace se contente d'additionner tous les coefficients sur la diagonale.  J'ai choisie de nommer les fonctions que retourne un nombre _Z et _mZ les fonctions qui retourne une matrice.

Exemple de sortie écran :

    A

   -1  +8i    -3  +4i    +4  +8i    +8  -7i    +4  +8i 
   -5  +8i    -5  +4i    +6  +4i    +8  -3i    -5  -5i 
   -9  -1i    +2  +2i    +6  -7i    -1  +6i    -3  -1i 
   -5  -3i    -9  -7i    +6  -1i    +4  -3i    -5  -7i 
   +8  -7i    -3  -3i    -1  +8i    -5  -9i    +8  -9i 




 Trace of the matrix A =   +12  -7i 



 Press return to continue
 Press X      to stop