Aller au contenu

Mathc matrices/c12an

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 **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_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);  
    
  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;
}
/* ------------------------------------ */
/* ------------------------------------ */

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=[
+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