Aller au contenu

Mathc matrices/02c

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(r,c),9.);
double **B_T  = transpose_mR(B, i_mR(c,r));

double **U    =                 i_mR(r,r);
double **U_T  =                 i_mR(r,r);
double **V    =                 i_mR(c,c);
double **V_T  =                 i_mR(c,c); 

double **U_TB =                 i_mR(r,c);   /* rr rc          U_T B   */
double **S    =                 i_mR(r,c);   /* rr rc cc   S = U_T B V */
double **US   =                 i_mR(r,c);   /* rr rc     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_Cn_mR(B,U);   
  svd_V_Cn_mR(B,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(U);
  f_mR(US);
  f_mR(U_T);
  f_mR(U_TB);  
  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+C2);

} while(stop_w());

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


Cet version fonctionne quand le nombre de colonnes est strictement supérieur au nombre de lignes..

 svd_U_Cn_mR(B,U); 
 svd_V_Cn_mR(B,V); 


Exemple de sortie écran :
 Copy/Past into the octave windows 


 B=[
-3.00,-3.00,-2.00,+2.00,-8.00;
-2.00,+4.00,-1.00,+8.00,+2.00;
-3.00,-1.00,-7.00,+4.00,-1.00]

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


 Press return to continue. 


 U :
+0.54810 -0.67715 -0.49098 
+0.49115 +0.73571 -0.46637 
+0.67702 +0.01447 +0.73582 

 S = U_T * B * V :
 +11.75989   -0.00000   +0.00000   +0.00000   +0.00000 
  +0.00000   +9.66688   -0.00000   -0.00000   -0.00000 
  -0.00000   -0.00000   -4.82249   -0.00000   +0.00000 

 V:
-0.39606 +0.05344 -0.04111 +0.00000 +0.91503 
-0.03033 +0.51307 +0.23398 +0.82464 +0.00000 
-0.53797 +0.05351 +0.76774 -0.27886 -0.21218 
+0.65762 +0.47474 +0.36696 -0.36452 +0.25860 
-0.34690 +0.71110 -0.46849 -0.33065 -0.22544 

 Press return to continue. 


 B :
    -3.000     -3.000     -2.000     +2.000     -8.000 
    -2.000     +4.000     -1.000     +8.000     +2.000 
    -3.000     -1.000     -7.000     +4.000     -1.000 

 B = U * S * V_T 
    -3.000     -3.000     -2.000     +2.000     -8.000 
    -2.000     +4.000     -1.000     +8.000     +2.000 
    -3.000     -1.000     -7.000     +4.000     -1.000 

 Press return to continue.