Mathc matrices/c12b7
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 **U = i_mR(r,r);
double **US = i_mR(r,c); /* rr rc */
double **U_T = i_mR(r,r);
double **U_TA = i_mR(r,c); /* rr rc */
double **V = i_mR(c,c);
double **V_T = i_mR(c,c);
double **S = i_mR(r,c);
clrscrn();
printf(" Copy/Past into the octave windows \n\n\n");
p_Octave_mR(A,"A",P2);
printf(" [U, S, V] =svd (A,10)\n\n\n");
stop();
clrscrn();
svd_U_Cn_mR(A,U);
svd_V_Cn_mR(A,V);
printf(" U :");
p_mR(U ,S10,P6,C10);
printf(" V ");
p_mR(V,S10,P6,C10);
printf(" S = U_T * A * V :");
transpose_mR( U,U_T);
mul_mR(U_T,A,U_TA);
mul_mR(U_TA,V,S);
p_mR(S,S10,P5,C10);
stop();
clrscrn();
printf(" A :");
p_mR(A ,S10,P6,C10);
printf(" A = U * S * V_T ");
transpose_mR(V,V_T);
mul_mR(U,S,US);
mul_mR(US,V_T,A);
p_mR(A,S10,P6,C10);
f_mR(A);
f_mR(U);
f_mR(US);
f_mR(U_T);
f_mR(U_TA);
f_mR(V);
f_mR(V_T);
f_mR(S);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
int i;
do
{
i = rp_I(R3)+R1;
fun(i,i+C3);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Dans cet exemple on vérifie que A = U * S * V_T.
Exemple de sortie écran :
Copy/Past into the octave windows
A=[
+6.00,-5.00,-9.00,-1.00,-9.00,-7.00,+8.00;
+8.00,+2.00,-3.00,+6.00,-5.00,-1.00,+6.00;
+8.00,-9.00,-7.00,-1.00,-7.00,-1.00,-7.00;
+2.00,-9.00,+6.00,+6.00,-5.00,+2.00,+8.00]
[U, S, V] =svd (A,10)
Press return to continue.
U :
+0.697032 -0.052053 -0.435660 -0.567130
+0.398267 +0.271334 -0.406011 +0.776477
+0.499582 -0.621376 +0.550049 +0.248506
+0.325495 +0.733185 +0.585493 -0.117010
V
-0.493283 -0.103373 +0.024085 +0.573255 +0.354196 -0.255488 -0.561344
+0.415216 -0.012768 +0.733636 +0.402661 -0.327467 -0.057098 -0.109646
+0.369971 +0.527650 -0.397873 +0.041853 -0.212080 -0.543889 -0.483772
-0.129149 +0.420736 -0.079756 +0.537120 +0.000000 +0.000000 +0.653231
+0.549656 -0.012839 +0.068513 +0.008454 +0.822028 +0.000000 +0.000000
+0.210437 +0.136934 -0.337796 +0.340570 +0.000000 +0.767554 -0.000000
-0.290352 +0.717497 +0.421585 -0.320832 +0.215877 +0.215664 -0.110110
S = U_T * A * V :
-24.35920 +0.00000 -0.00000 +0.00000 -0.00000 +0.00000 -0.00000
-0.00000 +15.92576 +0.00000 +0.00000 +0.00000 +0.00000 -0.00000
-0.00000 +0.00000 -12.06812 +0.00000 +0.00000 +0.00000 -0.00000
-0.00000 +0.00000 +0.00000 +7.95991 +0.00000 +0.00000 +0.00000
Press return to continue.
A :
+6.000000 -5.000000 -9.000000 -1.000000 -9.000000 -7.000000 +8.000000
+8.000000 +2.000000 -3.000000 +6.000000 -5.000000 -1.000000 +6.000000
+8.000000 -9.000000 -7.000000 -1.000000 -7.000000 -1.000000 -7.000000
+2.000000 -9.000000 +6.000000 +6.000000 -5.000000 +2.000000 +8.000000
a = U * S * V_T
+6.000000 -5.000000 -9.000000 -1.000000 -9.000000 -7.000000 +8.000000
+8.000000 +2.000000 -3.000000 +6.000000 -5.000000 -1.000000 +6.000000
+8.000000 -9.000000 -7.000000 -1.000000 -7.000000 -1.000000 -7.000000
+2.000000 -9.000000 +6.000000 +6.000000 -5.000000 +2.000000 +8.000000
Press return to continue
Press X to stop