Mathc matrices/c12an5

Un livre de Wikilivres.


Application


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


cgn6a.c
/* ------------------------------------ */
/*  Save as :   cgn6a.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);

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_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();   

/* 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+R6);

} while(stop_w());

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



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


 B=[
+4.00,+2.00;
+2.00,+2.00;
-3.00,-1.00;
+6.00,+4.00;
+4.00,-9.00;
-9.00,-1.00;
+2.00,+4.00;
+2.00,-9.00]

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


 Press return to continue. 



 ------------------------------------
 U :
-0.15613 -0.29739 
-0.14794 -0.14420 
+0.08216 +0.22528 
-0.30407 -0.44159 
+0.61248 -0.34677 
+0.10674 +0.68483 
-0.28769 -0.13522 
+0.62067 -0.19359 

 S :
+14.28696 
+13.03391 

 V:
+0.05852 +0.99829 
+0.99829 -0.05852 

 Press return to continue. 


 ------------------------------------
 S :
+14.28696 
+13.03391 

 S = U_T * B * V :
 -14.28696   -0.00000 
  +0.00000  -13.03391 


 Press return to continue
 Press X      to stop