Mathc matrices/h12b
Bibliothèque
Installer ce fichier dans votre répertoire de travail.
/* Save as : vdsvdrn.h */
/* ------------------------------------ */
void svd_V_Rn_uv_mR(
double **A,
double **V
int i; 
int r = rsize_R(A);
int c = csize_R(A);
double **A_T = i_mR(c,r); 
double **AA_T = i_mR(r,r);
double **EigsValue = i_mR(r,C1);
double **eignV = i_mR(r,r);
double **Ab;
double **b = m0_mR(i_mR(r,C1));
double **Ide = eye_mR(i_mR(r,r));
double **sIde = i_mR(r,r);
double **AA_TmnssIde = i_mR(r,r);
 eigs_value_AA_T_uv_mR(A, eignValue); if(c > r)
 eigs_value_AA_T_uv_mR(A_T,eignValue); if(r > c)
 eigs_value_AA_T_uv_mR(A,EigsValue); 
 transpose_mR(A,A_T) ; 
 mul_mR(A,A_T,AA_T);
 for(i = R1; i <= rsize_R(EigsValue); i++)
 smul_mR(EigsValue[i][C1],Ide,sIde);
 MmnsD_mR(AA_T,sIde,AA_TmnssIde);
 Ab = c_A_b_Ab_mR(AA_TmnssIde,b,i_Abr_Ac_bc_mR(r,r,C1));
 gj_freevariable_eignvector_uv_mR(Ab,eignV);
 c_c_mR(eignV,C2,V,i); 
 } 
 Normalize_uv_mR(V); 
 f_mR(EigsValue);
 f_mR(eignV);
 f_mR(A_T); 
 f_mR(AA_T);
 f_mR(Ab);
 f_mR(b);
 f_mR(Ide);
 f_mR(sIde);
 f_mR(AA_TmnssIde);
/* ------------------------------------ */
void svd_U_Rn_uv_mR(
double **A,
double **U
int i;
int r = rsize_R(A);
int c = csize_R(A);
double **A_T = i_mR(c,r); 
double **A_TA = i_mR(c,c);
double **EigsValue = i_mR(r,C1);
double **eignV = i_mR(c,r);
double **Ab;
double **b = m0_mR(i_mR(c,C1));
double **Ide = eye_mR(i_mR(c,c));
double **sIde = i_mR(c,c);
double **A_TAmnssIde = i_mR(c,c);
 eigs_value_AA_T_uv_mR(A, eignValue); if(c > r)
 eigs_value_AA_T_uv_mR(A_T,eignValue); if(r > c)
 eigs_value_AA_T_uv_mR(A,EigsValue);
 transpose_mR(A,A_T);
 mul_mR(A_T,A,A_TA);
 for(i = R1; i <= rsize_R(EigsValue); i++)
 smul_mR(EigsValue[i][C1],Ide,sIde);
 MmnsD_mR(A_TA,sIde,A_TAmnssIde);
 Ab = i_Abr_Ac_bc_mR(rsize_R(A_TAmnssIde),
 csize_R(A_TAmnssIde),
 csize_R(b));
 c_A_b_Ab_mR(A_TAmnssIde,b, Ab); 
 gj_freevariable_eignvector_uv_mR(Ab,eignV);
 c_c_mR(eignV,C2,U,i);

Normalize_uv_mR(U); 
 f_mR(EigsValue);
 f_mR(eignV);
 f_mR(A_TA);
 f_mR(Ab);
 f_mR(b);
 f_mR(Ide);
 f_mR(sIde);
 f_mR(A_TAmnssIde);
/* ------------------------------------ */
double **pseudo_Rn_uv_mR(
double **A,
double **Pinv,
double factor_E
int r = rsize_R(A);
int c = csize_R(A);
double **a = smul_mR(factor_E,A,
 i_mR(r,c));
double **a_T = transpose_mR(a,
 i_mR(c,r));
double **U = i_mR(r,c);
double **U_T = i_mR(c,r);
double **V = i_mR(c,c);
double **U_TA = i_mR(c,c);
double **S = i_mR(c,c);
double **S_T = i_mR(c,c);
double **invS_T = i_mR(c,c);
double **VS_T = i_mR(c,c); 
 svd_U_Rn_uv_mR(a_T,U); 
 svd_V_Rn_uv_mR(a_T,V); 
/* S = U_T * A * V */ 
 transpose_mR( U,U_T);
 mul_mR(U_T,A,U_TA);
 mul_mR(U_TA,V,S); 
/* invS_T = */ 
 transpose_mR(S,S_T);
 svd_inv_D_uv_mR(S_T,invS_T);
/* PseudoInverse = V * invS_T * U_T */ 
 mul_mR(V,invS_T,VS_T);
 mul_mR(VS_T,U_T,Pinv); 
 f_mR(U);
 f_mR(U_T); 
 f_mR(V); 
 f_mR(a); 
 f_mR(a_T);
 f_mR(U_TA);
 f_mR(S); 
 f_mR(S_T);
 f_mR(invS_T);
 f_mR(VS_T); 
 return(Pinv);
/* ------------------------------------ */

Mathc matrices/c12an
Installer et compiler ces fichiers dans votre répertoire de travail.
/* ------------------------------------ */
/* Save as : cgn0.c */
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 **S = i_mR(r,C1);
double **U = i_mR(c,r);
double **V = i_mR(r,r);
 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_uv_mR(B_T,U); 
 svd_V_Rn_uv_mR(B_T,V); 
 svd_value_uv_mR(B,S);
 printf(" U :");
 p_mR(U,S5,P5,C10); 
 printf(" S :");
 p_mR(S,S5,P5,C10);
 printf(" V:");
 p_mR(V,S5,P5,C10); 
 f_mR(B_T);
 f_mR(B);
 f_mR(S); 
 f_mR(U);
 f_mR(V); 
/* ------------------------------------ */
int main(void)
time_t t;
 srand(time(&t));
int i;
do
 i = rp_I(R3)+R1;
 fun(i,i+R0);
} while(stop_w());
 return 0;
/* ------------------------------------ */

Exemple de sortie écran :
 Copy/Past into the octave windows 
 B=[
+4.00,-3.00,-9.00,+2.00;
-5.00,-7.00,-9.00,-3.00;
+8.00,+4.00,-7.00,-5.00;
+4.00,-5.00,+2.00,-7.00]
 [U, S, V] =svd (B,10)
 Press return to continue. 
 ------------------------------------ 
 U :
+0.58066 -0.02116 -0.36189 +0.72898 
+0.58470 -0.68441 +0.17275 -0.39984 
+0.53936 +0.70325 -0.09066 -0.45421 
+0.17335 +0.19124 +0.91158 +0.32000 
 S :
+15.93854 
+12.29004 
+9.72247 
+4.73198 
 V:
-0.27653 +0.79157 -0.06271 -0.54132 
+0.28511 +0.54607 +0.51881 +0.59276 
+0.87317 +0.14726 -0.42787 -0.18115 
+0.28252 -0.23141 +0.73745 -0.56816 
 Press return to continue
 Press X to stop

Mathc matrices/c12a2
Application
Installer et compiler ces fichiers dans votre répertoire de travail.
/* ------------------------------------ */
/* Save as : cgn2.c */
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 **S = i_mR(r,C1);
double **U = i_mR(c,r);
double **V = i_mR(r,r);
 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_uv_mR(B_T,U); 
 svd_V_Rn_uv_mR(B_T,V); 
 svd_value_uv_mR(B,S);
 printf(" U :");
 p_mR(U,S5,P5,C10); 
 printf(" S :");
 p_mR(S,S5,P5,C10);
 printf(" V:");
 p_mR(V,S5,P5,C10); 
 f_mR(B_T);
 f_mR(B);
 f_mR(S); 
 f_mR(U);
 f_mR(V); 
/* ------------------------------------ */
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;
/* ------------------------------------ */

Exemple de sortie écran :
 Copy/Past into the octave windows 
 B=[
+8.00,-9.00,-3.00,-7.00;
+4.00,+8.00,+8.00,+2.00;
-5.00,-7.00,-3.00,-1.00;
-7.00,+4.00,-5.00,-1.00;
-1.00,+8.00,+2.00,-3.00;
+8.00,-1.00,+8.00,+4.00]
 [U, S, V] =svd (B,10)
 Press return to continue. 
 ------------------------------------ 
 U :
-0.40288 +0.62176 +0.61771 +0.01959 
+0.62771 +0.04994 +0.13227 +0.26016 
-0.43030 -0.04785 -0.35711 +0.79389 
-0.13459 -0.52493 +0.15695 -0.24204 
+0.28979 -0.26108 +0.57773 +0.49226 
+0.39550 +0.51470 -0.33912 +0.02774 
 S :
+19.20771 
+17.24848 
+8.58162 
+2.98489 
 V:
+0.27362 -0.78072 -0.33409 -0.45165 
+0.67911 +0.55451 -0.41802 -0.23789 
+0.62151 -0.28396 +0.24074 +0.68931 
+0.27870 +0.04856 +0.80975 -0.51408 
 Press return to continue
 Press X to stop

Mathc matrices/c12a3
Application
Installer et compiler ces fichiers dans votre répertoire de travail.
/* ------------------------------------ */
/* Save as : cgn2a.c */
/* ------------------------------------ */
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 **S = i_mR(r,C1);
double **U = i_mR(c,r);
double **V = i_mR(r,r);
double **U_T = i_mR(r,c);
double **U_TB = i_mR(r,r); /* rc cr U_T*B */
double **S_2 = i_mR(r,r); /* rc cr rr 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_uv_mR(B_T,U); 
 svd_V_Rn_uv_mR(B_T,V); 
 svd_value_uv_mR(B,S);
 printf(" U :");
 p_mR(U,S5,P5,C10); 
 printf(" S :");
 p_mR(S,S5,P5,C10);
 printf(" V:");
 p_mR(V,S5,P5,C10); 
 stop();
 clrscrn(); 
/* S = U_T * B * V : */ 
 transpose_mR( U,U_T);
 mul_mR(U_T,B,U_TB);
 mul_mR(U_TB,V,S_2);
 printf(" S :");
 p_mR(S,S5,P5,C10);
 printf(" S = U_T * B * V :");
 p_mR(S_2,S10,P5,C10); 
 f_mR(B);
 f_mR(B_T);
 f_mR(S); 
 f_mR(U);
 f_mR(V); 
 f_mR(U_T);
 f_mR(U_TB);
 f_mR(S_2); 
/* ------------------------------------ */
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;
/* ------------------------------------ */