Mathc matrices/02b
Apparence
Installer et compiler ces fichiers dans votre répertoire de travail.
c00a.c |
---|
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define RB R5
#define CB C2
/* ------------------------------------ */
int main(void)
{
double b[RB*CB]={
-1.00,-5.00,
-1.00,+6.00,
-2.00,+8.00,
+3.00,+1.00,
+4.00,-5.00
};
double **B = ca_A_mR(b, i_mR(RB,CB));
double **B_T = transpose_mR(B, i_mR(CB,RB));
double **U = i_mR(RB,CB);
double **US = i_mR(RB,CB); /* rc cc US = U S */
double **U_T = i_mR(CB,RB);
double **U_TB = i_mR(CB,CB); /* cr rc U_T B */
double **V = i_mR(CB,CB);
double **V_T = i_mR(CB,CB);
double **S = i_mR(CB,CB); /* cr rc cc S = U_T B V */
clrscrn();
printf(" Copy/Past into the octave windows \n\n\n");
p_Octave_mR(B,"B",P2);
printf(" [U, S, V] =svd (B,10)\n\n\n");
stop();
clrscrn();
svd_U_Rn_mR(B_T,U);
svd_V_Rn_mR(B_T,V);
printf(" U :");
smul_c1_mR(-1.,C1,U);
smul_c1_mR(-1.,C2,U);
p_mR(U, S5,P5,C10);
printf(" V:");
smul_c1_mR(-1.,C1,V);
smul_c1_mR(-1.,C2,V);
p_mR(V,S5,P5,C10);
printf(" S = U_T * B * V :");
transpose_mR(U,U_T);
mul_mR(U_T,B,U_TB);
mul_mR(U_TB,V,S);
p_mR(S, S10,P5,C10);
stop();
clrscrn();
printf(" B :");
p_mR(B ,S10,P3,C10);
printf(" B = U * S * V_T ");
transpose_mR(V,V_T);
mul_mR(U,S,US);
mul_mR(US,V_T,B);
p_mR(B, S10,P3,C10);
stop();
f_mR(B);
f_mR(B_T);
f_mR(U);
f_mR(US);
f_mR(U_T);
f_mR(U_TB);
f_mR(V);
f_mR(V_T);
f_mR(S);
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Cet version fonctionne quand le nombre de lignes est supérieur ou égal au nombre de colonnes..
svd_U_Rn_mR(B_T,U); svd_V_Rn_mR(B_T,V);
C'est la fonction "smul_c1_mR(-1.,C1,V);" qui me permet de corriger les signes d'une colonne.
Exemple de sortie écran :
Copy/Past into the octave windows
B=[
-1.00,-5.00;
-1.00,+6.00;
-2.00,+8.00;
+3.00,+1.00;
+4.00,-5.00]
[U, S, V] =svd (B,10)
Press return to continue.
U :
+0.36211 +0.47752
-0.47888 -0.11985
-0.65194 -0.02248
-0.01598 -0.67227
+0.46289 -0.55242
V:
+0.25493 -0.96696
-0.96696 -0.25493
S = U_T * B * V :
+12.64768 -0.00000
+0.00000 +4.69428
Press return to continue.
B :
-1.000 -5.000
-1.000 +6.000
-2.000 +8.000
+3.000 +1.000
+4.000 -5.000
B = U * S * V_T
-1.000 -5.000
-1.000 +6.000
-2.000 +8.000
+3.000 +1.000
+4.000 -5.000
Press return to continue.