Mathc matrices/c12a3

Un livre de Wikilivres.
Aller à la navigation Aller à la recherche


Sommaire


Installer et compiler ces fichiers dans votre répertoire de travail.


Crystal Clear mimetype source c.png cgn2a.c
'
/* ------------------------------------ */
/*  Save as :   cgn2a.c                    */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
void fun(int r,int c)
{
double **B     = r_mR(i_mR(c,r),9.);

double **A     = 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    */
double **U_TBV = i_mR(r,r);    /* rc cr rr */


  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(A,U);    
  svd_V_Rn_uv_mR(A,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();   
  
  transpose_mR( U,U_T);
  mul_mR(U_T,B,U_TB);
  mul_mR(U_TB,V,U_TBV);
 
  printf(" S :");
  p_mR(S,S5,P5,C10);
  
  printf(" S = U_T * B * V :");
  p_mR(U_TBV,S10,P5,C10);  
    
  f_mR(B);
  f_mR(A);

  f_mR(S); 
  f_mR(U);
  f_mR(V); 
   
  f_mR(U_T);
  f_mR(U_TB);
  f_mR(U_TBV);  
}
/* ------------------------------------ */
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=[
-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.