Mathc matrices/02a
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 **B = r_mR( i_mR(r,c),9.);
double **B_T = transpose_mR(B, i_mR(c,r));
double **U = i_mR(r,c);
double **U_T = i_mR(c,r);
double **V = i_mR(c,c);
double **V_T = i_mR(c,c);
double **U_TB = i_mR(c,c); /* cr rc U_T B */
double **S = i_mR(c,c); /* cr rc cc S = U_T B V */
double **US = i_mR(r,c); /* rc cc US = U S */
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 :");
p_mR(U, 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);
printf(" V:");
p_mR(V, S5,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);
f_mR(B);
f_mR(B_T);
f_mR(V);
f_mR(V_T);
f_mR(U);
f_mR(U_T);
f_mR(S);
f_mR(U_TB);
f_mR(US);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
int i;
do
{
i = rp_I(R3)+R1;
fun(i+R3,i);
} while(stop_w());
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); Exemple de sortie écran :
Copy/Past into the octave windows
B=[
+4.00,+6.00,-3.00;
+2.00,-8.00,-1.00;
-8.00,+7.00,-6.00;
+9.00,-9.00,-7.00;
-3.00,+2.00,-1.00;
-3.00,+3.00,-5.00]
[U, S, V] =svd (B,10)
Press return to continue.
U :
-0.11067 +0.39506 +0.76774
+0.39399 +0.01597 -0.45446
-0.54915 +0.50302 -0.37976
+0.67071 +0.62945 -0.02076
-0.18102 +0.07087 -0.15798
-0.21987 +0.43521 -0.18556
S = U_T * B * V :
-18.97666 -0.00000 -0.00000
-0.00000 -11.11793 +0.00000
+0.00000 -0.00000 +7.95474
V:
-0.63117 -0.15604 +0.75978
+0.77558 -0.13906 +0.61574
+0.00957 +0.97791 +0.20879
Press return to continue.
B :
+4.000 +6.000 -3.000
+2.000 -8.000 -1.000
-8.000 +7.000 -6.000
+9.000 -9.000 -7.000
-3.000 +2.000 -1.000
-3.000 +3.000 -5.000
B = U * S * V_T
+4.000 +6.000 -3.000
+2.000 -8.000 -1.000
-8.000 +7.000 -6.000
+9.000 -9.000 -7.000
-3.000 +2.000 -1.000
-3.000 +3.000 -5.000
Press return to continue
Press X return to stop