Aller au contenu

Mathc complexes/00p

Un livre de Wikilivres.

Application

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

c00a.c
/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
void fun(int rc)
{
double **A      =         r_mZ(    i_mZ(rc,rc),9);
double **Q      =                  i_mZ(rc,rc);
double **R      =                  i_mZ(rc,rc);	

double **A_CT    = ctranspose_mZ(A, i_mZ(rc,rc));
double **Q_CT    =                  i_mZ(rc,rc);
double **R_CT    =                  i_mZ(rc,rc);	

  clrscrn();
  printf(" A : ");
  p_mZ(A, S8,P4, S8,P4, C6);
  QR_mZ(A,Q,R);    
  printf(" Q :");
  p_mZ(Q, S8,P4, S8,P4, C6);  
  printf(" R :");
  p_mZ(R, S8,P4, S8,P4, C6);
  stop();
  
  clrscrn();
  printf(" A_CT : Conjugate Transpose");
  p_mZ(A_CT, S8,P4, S8,P4, C6);
  QR_mZ(A_CT,Q_CT,R_CT);    
  printf(" Q_CT :");
  p_mZ(Q_CT, S8,P4, S8,P4, C6);  
  printf(" R_CT :");
  p_mZ(R_CT, S8,P4, S8,P4, C6);
  stop();

  clrscrn();
  printf(" Q :");
  p_mZ(Q, S8,P4, S8,P4, C6);  
  printf(" R :");
  p_mZ(R, S8,P4, S8,P4, C6);   
  printf(" Q_CT :");
  p_mZ(Q_CT, S8,P4, S8,P4, C6);  
  printf(" R_CT :");
  p_mZ(R_CT, S8,P4, S8,P4, C6);
  stop();
    
  clrscrn();
  printf(" A :");
  p_mZ(A, S8,P4, S8,P4, C6); 
  printf(" A = Q * R  :");  
  mul_mZ(Q,R, A);
  p_mZ(A, S8,P4, S8,P4, C6);  

  printf(" A_CT :");
  p_mZ(A_CT, S8,P4, S8,P4, C6); 
  printf(" A_CT = Q_CT * R_CT  :");  
  mul_mZ(Q_CT,R_CT, A_CT);
  p_mZ(A_CT, S8,P4, S8,P4, C6); 
       
  f_mZ(A);
  f_mZ(Q);
  f_mZ(R);
  f_mZ(A_CT);
  f_mZ(Q_CT);
  f_mZ(R_CT);
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));
  
   do 
         fun(rp_I(RC3)+RC1);
        
    while(stop_w());
        
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


La QR décomposition d'une matrice et de sa conjuguée transposée non aucun lien.

Exemple de sortie écran :

 A : 
 -6.0000 -4.0000i  +1.0000 -3.0000i  +6.0000 -2.0000i 
 -6.0000 +1.0000i  +9.0000 -7.0000i  +1.0000 +6.0000i 
 -3.0000 -7.0000i  +1.0000 +2.0000i  -8.0000 -3.0000i 

 Q :
 -0.4949 -0.3299i  -0.3683 -0.2843i  +0.6470 -0.1056i 
 -0.4949 +0.0825i  +0.6852 -0.4493i  -0.1786 -0.2123i 
 -0.2474 -0.5774i  -0.3335 -0.0304i  -0.6986 -0.0721i 

 R :
+12.1244 +0.0000i  -5.9385 +4.6188i  +1.4021 -3.9590i 
 -0.0000 +0.0000i  +9.4022 -0.0000i  -0.8921 +7.7605i 
 +0.0000 +0.0000i  +0.0000 -0.0000i  +8.4462 +0.0000i 

 Press return to continue. 


 A_CT : Conjugate Transpose
 -6.0000 +4.0000i  -6.0000 -1.0000i  -3.0000 +7.0000i 
 +1.0000 +3.0000i  +9.0000 +7.0000i  +1.0000 -2.0000i 
 +6.0000 +2.0000i  +1.0000 -6.0000i  -8.0000 +3.0000i 

 Q_CT :
 -0.5941 +0.3961i  -0.2956 -0.3764i  -0.0285 +0.5102i 
 +0.0990 +0.2970i  +0.5928 +0.4373i  -0.2688 +0.5358i 
 +0.5941 +0.1980i  -0.2210 -0.4236i  -0.6128 +0.0632i 

 R_CT :
+10.0995 +0.0000i  +5.5448 -2.7724i  -0.0990 -0.0990i 
 -0.0000 -0.0000i +12.8673 +0.0000i  -1.5330 -8.8733i 
 -0.0000 -0.0000i  +0.0000 -0.0000i  +7.4090 -0.0000i 

 Press return to continue. 


 Q :
 -0.4949 -0.3299i  -0.3683 -0.2843i  +0.6470 -0.1056i 
 -0.4949 +0.0825i  +0.6852 -0.4493i  -0.1786 -0.2123i 
 -0.2474 -0.5774i  -0.3335 -0.0304i  -0.6986 -0.0721i 

 R :
+12.1244 +0.0000i  -5.9385 +4.6188i  +1.4021 -3.9590i 
 -0.0000 +0.0000i  +9.4022 -0.0000i  -0.8921 +7.7605i 
 +0.0000 +0.0000i  +0.0000 -0.0000i  +8.4462 +0.0000i 

 Q_CT :
 -0.5941 +0.3961i  -0.2956 -0.3764i  -0.0285 +0.5102i 
 +0.0990 +0.2970i  +0.5928 +0.4373i  -0.2688 +0.5358i 
 +0.5941 +0.1980i  -0.2210 -0.4236i  -0.6128 +0.0632i 

 R_CT :
+10.0995 +0.0000i  +5.5448 -2.7724i  -0.0990 -0.0990i 
 -0.0000 -0.0000i +12.8673 +0.0000i  -1.5330 -8.8733i 
 -0.0000 -0.0000i  +0.0000 -0.0000i  +7.4090 -0.0000i 

 Press return to continue. 

 A :
 -6.0000 -4.0000i  +1.0000 -3.0000i  +6.0000 -2.0000i 
 -6.0000 +1.0000i  +9.0000 -7.0000i  +1.0000 +6.0000i 
 -3.0000 -7.0000i  +1.0000 +2.0000i  -8.0000 -3.0000i 

 A = Q * R  :
 -6.0000 -4.0000i  +1.0000 -3.0000i  +6.0000 -2.0000i 
 -6.0000 +1.0000i  +9.0000 -7.0000i  +1.0000 +6.0000i 
 -3.0000 -7.0000i  +1.0000 +2.0000i  -8.0000 -3.0000i 

 A_CT :
 -6.0000 +4.0000i  -6.0000 -1.0000i  -3.0000 +7.0000i 
 +1.0000 +3.0000i  +9.0000 +7.0000i  +1.0000 -2.0000i 
 +6.0000 +2.0000i  +1.0000 -6.0000i  -8.0000 +3.0000i 

 A_CT = Q_CT * R_CT  :
 -6.0000 +4.0000i  -6.0000 -1.0000i  -3.0000 +7.0000i 
 +1.0000 +3.0000i  +9.0000 +7.0000i  +1.0000 -2.0000i 
 +6.0000 +2.0000i  +1.0000 -6.0000i  -8.0000 +3.0000i 


 Press   return to continue
 Press X return to stop