Mathc matrices/01l
Apparence
Installer ce fichier 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_T, i_mR(r,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<=r;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<=r;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<=r;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(R4,C6);
} 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:
+4 +5 +5 +1 -5 +9
-5 -5 +5 -3 -5 +7
-3 +1 +8 -2 +2 +6
+4 +4 -7 -4 +9 -2
Singular values:
+19.90045
+11.37326
+8.93539
+5.07739
Press return to continue.
Sum of the singular values of A : s = 45.286
The contribution of each singular value in percentage
100 Svalues[1]/s = +43.943%
100 Svalues[2]/s = +25.114%
100 Svalues[3]/s = +19.731%
100 Svalues[4]/s = +11.212%
The contribution of each singular value in proportion
Svalues[1]/s = +0.439
Svalues[2]/s = +0.251
Svalues[3]/s = +0.197
Svalues[4]/s = +0.112
Press return to continue
Press X return to stop