Mathc matrices/c12a4
Apparence
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(c,r),9.);
double **B_T = transpose_mR(B, i_mR(r,c));
double **U_TB = i_mR(r,r); /* rc cr */
double **U = i_mR(c,r);
double **U_T = i_mR(r,c);
double **US = i_mR(c,r); /* cr rr U*S */
double **V = i_mR(r,r);
double **V_T = i_mR(r,r);
double **S = i_mR(r,r);
clrscrn();
svd_U_Rn_mR(B_T,U);
svd_V_Rn_mR(B_T,V);
/* S = U_T * B * V */
transpose_mR(U,U_T);
mul_mR(U_T,B,U_TB);
mul_mR(U_TB,V,S);
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(U);
f_mR(U_T);
f_mR(U_TB);
f_mR(US);
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+R2);
} while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Cet version fonctionne quand il y a plus de lignes que de colonnes..
svd_U_Rn_mR(B_T,U); svd_V_Rn_mR(B_T,V);
Exemple de sortie écran :
B :
-1.000 +2.000 -5.000 -5.000
-7.000 +4.000 +6.000 -3.000
-7.000 -5.000 +8.000 -5.000
+6.000 +2.000 +6.000 -9.000
+2.000 +4.000 -1.000 +4.000
-3.000 +2.000 +6.000 +6.000
B = U * S * V_T
-1.000 +2.000 -5.000 -5.000
-7.000 +4.000 +6.000 -3.000
-7.000 -5.000 +8.000 -5.000
+6.000 +2.000 +6.000 -9.000
+2.000 +4.000 -1.000 +4.000
-3.000 +2.000 +6.000 +6.000
Press return to continue
Press X to stop