Aller au contenu

Mathc matrices/01i

Un livre de Wikilivres.


Application

Installer et compiler ces fichiers dans votre répertoire de travail.

c00a.c
/* ------------------------------------ */
/*  Save as :   c00a.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r,int c)
{
double **A       =         r_mR(   i_mR(r,c),9.);
double **A_T     = transpose_mR(A, i_mR(c,r));
double **Svalues =      svds_mR(A, i_mR(c,C1));    

double s = 0;
int    i = 0;

  clrscrn(); 
  printf(" A:");
  p_mR(A, S5,P0,C10);
    
  printf(" Singular values:");
  p_mR(Svalues, S5,P5,C10);
  stop();
  
  clrscrn(); 

  for(i=R1;i<=c;i++)
  
      s += Svalues[i][C1];
      
  printf(" Sum of the singular values of A : s = %.3f\n\n\n", s); 
  

  printf(" The contribution of each singular value in percentage\n\n");
  
  for(i=R1;i<=c;i++)
  
      printf(" 100 Svalues[%d]/s = %+.3f%%\n",i,(100*Svalues[i][C1])/s);


  printf("\n\n\n"
         " The contribution of each singular value in proportion\n\n");
  
  for(i=R1;i<=c;i++)
  
      printf(" Svalues[%d]/s = %+.3f\n",i,(Svalues[i][C1])/s);
                  
  f_mR(A);
  f_mR(A_T);
  f_mR(Svalues);    
}
/* ------------------------------------ */
int main(void)
{
time_t t;

  srand(time(&t));

do
{
  
  fun(R6,C4);

} while(stop_w());

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Dans cet exemple, nous étudierons la contribution de chaque valeur singulière de la matrice. Si la matrice représente une image, nous pourrions supprimer toutes les valeurs singulières de faible contribution ainsi que leurs vecteurs singuliers correspondants afin de compresser l'image sans la dégrader.
Exemple de sortie écran :
 A:
   +8    +2    -6    -5 
   -6    +7    +5    -3 
   +5    -9    -8    +6 
   +4    -6    -8    +5 
   -6    +9    -5    -1 
   +7    -4    -7    +3 

 Singular values:
+24.86543 
+12.23045 
+9.54881 
+1.39522 

 Press return to continue. 


 Sum of the singular values of A : s = 48.040


 The contribution of each singular value in percentage

 100 Svalues[1]/s = +51.760%
 100 Svalues[2]/s = +25.459%
 100 Svalues[3]/s = +19.877%
 100 Svalues[4]/s = +2.904%



 The contribution of each singular value in proportion

 Svalues[1]/s = +0.518
 Svalues[2]/s = +0.255
 Svalues[3]/s = +0.199
 Svalues[4]/s = +0.029

 Press   return to continue
 Press X return to stop