Aller au contenu

Mathc matrices/cq054

Un livre de Wikilivres.


SommaireUtilise la commande "Retour en Arrière" de ton navigateur.


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


c01c.c
/* ------------------------------------ */
/*  Save as :   c01c.c                    */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R5
#define   CA C3
/* ------------------------------------ */
#define FACTOR_E        +1.E-0         
/* ------------------------------------ */
void fun(void)
{
double tA[RA*CA]={
/* x**0   x**1  x**2  */
   1,     .1,   .01,  
   1,     .2,   .04,   
   1,     .3,   .09,    
   1,     .4,   .16,    
   1,     .5,   .25
};

double tb[RA*C1]={
/*    y    */
     -0.19,
      0.32,
      1.04,
      2.47,
      3.74
};

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(" Fitting a linear Curve to Data :\n\n");
  printf(" A :");
  p_mR(A,S5,P2,C7);
  printf(" b :");
  p_mR(b,S5,P2,C7);
   
  printf(" Pinv = V * invS_T * U_T ");
  pseudo_Rn_mR(A,Pinv,FACTOR_E); 
  pE_mR(Pinv,S12,P4,C10);    
  stop();
  
  clrscrn();   
  printf(" x = Pinv * b ");   
  mul_mR(Pinv,b,Pinvb); 
  p_mR(Pinvb,S10,P4,C10);
  printf(" The Quadratic Curve to Data : \n\n"
         "  s = %+.2f %+.2f*t %+.2f*t**2\n\n"
            ,Pinvb[R1][C1],Pinvb[R2][C1],Pinvb[R3][C1]);       
  stop();  

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

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



Exemple de sortie écran :
 -----------------------------------
 Fitting a linear Curve to Data :

 A :
+1.00 +0.10 +0.01 
+1.00 +0.20 +0.04 
+1.00 +0.30 +0.09 
+1.00 +0.40 +0.16 
+1.00 +0.50 +0.25 

 b :
-0.19 
+0.32 
+1.04 
+2.47 
+3.74 

 Pinv = V * invS_T * U_T 
   +1.8000    -0.0000    -0.8000    -0.6000    +0.6000 
  -10.5714    +3.2857    +8.5714    +5.2857    -6.5714 
  +14.2857    -7.1429   -14.2857    -7.1429   +14.2857 

 Press return to continue. 


 -----------------------------------
 x = Pinv * b 
   -0.4120 
   +0.4529 
  +15.9286 

 The Quadratic Curve to Data : 

  s = -0.41 +0.45*t +15.93*t**2

 Press return to continue.