Mathc matrices/c21o

Un livre de Wikilivres.


Application ou Pseudo Inverse


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


c01a.c
/* ------------------------------------ */
/*  Save as :   c01a.c                    */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R3
#define   CA C2
/* ------------------------------------ */
#define FACTOR_E        +1.E-0         
/* ------------------------------------ */
void fun(void)
{
double tA[RA*CA]={
 1, -1, 
 3,  2, 
-2,  4
};

double tb[RA*C1]={
  4,
  1,
  3
};

double **A       = ca_A_mR(tA,i_mR(RA,CA));    
double **b       = ca_A_mR(tb,i_mR(RA,C1));
double **Pinv    =            i_mR(CA,RA);           
double **Pinvb   =            i_mR(CA,C1);          

  clrscrn();
  printf("Find the unique Least Squares Solution of Ax = b : \n\n");
  printf(" A :");
  p_mR(A,S5,P1,C7);
  printf(" b :");
  p_mR(b,S5,P1,C7);
   
  printf(" Pinv = V * invS_T * U_T ");
  pseudo_Rn_mR(A,Pinv,FACTOR_E); 
  pE_mR(Pinv,S12,P4,C10);   
  
  printf(" x = Pinv * b ");   
  mul_mR(Pinv,b,Pinvb); 
  p_mR(Pinvb,S10,P4,C10);  
  stop();  

  f_mR(b);   
  f_mR(A);
  f_mR(Pinv);
  f_mR(Pinvb); 
}
/* ------------------------------------ */
int main(void)
{
  
  fun();

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


Exemple de sortie écran :
 -----------------------------------
Find the unique Least Squares Solution of Ax = b : 

 A :
 +1.0  -1.0 
 +3.0  +2.0 
 -2.0  +4.0 

 b :
 +4.0 
 +1.0 
 +3.0 

 Pinv = V * invS_T * U_T 
   +0.0632    +0.2421    -0.1053 
   -0.0386    +0.1298    +0.1754 

 x = Pinv * b 
   +0.1789 
   +0.5018 

 Press return to continue.