Mathc matrices/c12a5

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 cgn2f.c
'
/* ------------------------------------ */
/*  Save as :   cgn2f.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 **U_TB    = i_mR(r,r);             /* rc cr*/


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

double **S       = i_mR(r,r);
double **T       = i_mR(r,r);
double **S_T     = i_mR(r,r);
double **U_T     = i_mR(r,c);

double **VS_T    = i_mR(r,r);          /* rr rr    */
double **VS_TU_T = i_mR(r,c);          /* rr rr rc */

double **VS_TU_TB = i_mR(r,r);          /* rr rr rc cr */

  clrscrn();
  printf(" Copy/Past into the octave windows \n\n\n");
  p_Octave_mR(B,"B",P2);
  printf("pinv(B)\n\n\n");
  stop();

  clrscrn();    
  svd_U_Rn_uv_mR(A,U);    
  svd_V_Rn_uv_mR(A,V);  

 /* S = U_T * B * V */ 
  transpose_mR( U,U_T);
  mul_mR(U_T,B,U_TB);
  mul_mR(U_TB,V,S);
  
  transpose_mR(S,T);
  svd_inv_D_uv_mR(T,S_T);  
  mul_mR(V,S_T,VS_T);
  mul_mR(VS_T,U_T,VS_TU_T);
  printf(" PseudoInverse = V * invS_T * U_T "); 
  p_mR(VS_TU_T,S10,P6,C10);  
  
  printf(" Ide = PseudoInverse * B ");   
  mul_mR(VS_TU_T,B,VS_TU_TB); 
  p_mR(VS_TU_TB,S10,P6,C10);   
    
  f_mR(B);
  f_mR(A);
  
  f_mR(U_TB); 
  
  f_mR(U);
  f_mR(V);   
  f_mR(S); 
  f_mR(T);
  
  f_mR(S_T); 
  f_mR(U_T);  
  f_mR(VS_T);  
  
  f_mR(VS_TU_T);
  f_mR(VS_TU_TB); 
}
/* ------------------------------------ */
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=[
+6.00,-9.00,+6.00;
+6.00,-3.00,-1.00;
+8.00,-3.00,+2.00;
-3.00,+2.00,+8.00;
+8.00,+8.00,-9.00]

pinv(B)


 Press return to continue. 


 ------------------------------------ 
 PseudoInverse = V * invS_T * U_T 
 +0.026280  +0.021775  +0.049295  +0.026483  +0.049595 
 -0.036176  -0.021542  +0.016123  +0.088165  +0.060228 
 +0.017345  -0.012610  +0.033799  +0.103693  +0.001535 

 Ide = PseudoInverse * B 
 +1.000000  +0.000000  -0.000000 
 -0.000000  +1.000000  +0.000000 
 +0.000000  -0.000000  +1.000000 


 Press return to continue
 Press X      to stop