Aller au contenu

Mathc matrices/c12a3

Un livre de Wikilivres.


Application


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    =                 i_mR(c,r);
double **U_T  =                 i_mR(r,c);
double **U_TB =                 i_mR(r,r);   /* rc cr         U_T*B   */
double **V    =                 i_mR(r,r);

double **S    =                 i_mR(r,C1);
double **SD   =                 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_mR(B_T,U);    
  svd_V_Rn_mR(B_T,V); 
      svds_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();   
  printf(" S :");
  p_mR(S,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,SD);
          p_mR(SD,S10,P5,C10);  
    
  f_mR(B);
  f_mR(B_T);
  f_mR(U);
  f_mR(U_T);
  f_mR(U_TB);
  f_mR(V); 
  f_mR(S);    
  f_mR(SD);  
}
/* ------------------------------------ */
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 :

 Copy/Past into the octave windows 


 B=[
-7.00,+4.00,+8.00;
-9.00,-9.00,-9.00;
+6.00,-9.00,-9.00;
-9.00,+6.00,-7.00;
-5.00,-9.00,-1.00]

 [U, S, V] =svd (B,10)


 Press return to continue. 


 U :
-0.35867 +0.42201 +0.43276 
+0.64431 +0.44275 +0.13610 
+0.56518 -0.42888 -0.17300 
+0.07319 +0.64281 -0.64800 
+0.36253 +0.16949 +0.58682 

 S :
+21.18893 
+16.66846 
+10.77922 

 V:
+0.11177 +0.96859 -0.22212 
+0.71470 -0.23366 -0.65925 
+0.69044 +0.08507 +0.71837 

 Press return to continue.