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


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


c00i.c
/* ------------------------------------ */
/*  Save as :   c00i.c                   */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R4
#define   CA C4
#define   Cb C1 
/* ------------------------------------ */
/* ------------------------------------ */
void fun(void)
{
double ab[RA*(CA+Cb)]={
/* x**0   x**1   x**2    x**3    y  */
   1,    -5.,   +25.,   -125.,  -3.00,
   1,    -2.,    +4.,     -8.,  +0.00,
   1,    +2.,    +4.,     +8.,  +3.00,
   1,    +3.,    +9.,    +27.,  -2.00,
};

double **Ab = ca_A_mR(ab,i_Abr_Ac_bc_mR(RA,CA,Cb));
double **A  = c_Ab_A_mR(Ab,i_mR(RA,CA));
double **b  = c_Ab_b_mR(Ab,i_mR(RA,Cb));

double **Q    = i_mR(RA,CA);
double **R    = i_mR(CA,CA);

double **invR = i_mR(CA,CA);
double **Q_T  = i_mR(CA,RA);


double **invR_Q_T = i_mR(CA,RA);
double **x        = i_mR(CA,Cb); // x invR * Q_T * b

  clrscrn();
  printf(" Fitting a Cubic equation Curve to Data :\n\n");
  printf(" A :");
  p_mR(A,S7,P2,C7);
  printf(" b :");
  p_mR(b,S7,P2,C7);
  printf(" Ab :");
  p_mR(Ab,S7,P2,C7);
  stop();
    
  clrscrn();
  QR_mR(A,Q,R);    
  printf(" Q :");
  p_mR(Q,S10,P4,C6);  
  printf(" R :");
  p_mR(R,S10,P4,C6);
  stop();

  clrscrn();
  transpose_mR(Q,Q_T);   
  printf(" Q_T :");
  pE_mR(Q_T,S7,P4,C6); 
  inv_mR(R,invR); 
  printf(" invR :");
  pE_mR(invR,S7,P4,C6);
  stop();
  
  clrscrn();
  printf(" Solving this system yields a unique\n"
         " least squares solution, namely   \n\n");
  mul_mR(invR,Q_T,invR_Q_T);
  mul_mR(invR_Q_T,b,x);
  printf(" x = invR * Q_T * b :");
  p_mR(x,S10,P2,C6);
  printf(" The Cubic equation Curve to Data : \n\n"
         "  s = %+.3f %+.3f*t %+.3f*t**2 %+.3f*t**2\n\n"
            ,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1]);  
  
  stop();
  
  f_mR(A);
  f_mR(b);
  f_mR(Ab);
  f_mR(Q);
  f_mR(Q_T);
  f_mR(R);
  f_mR(invR);  
  f_mR(invR_Q_T); 
  f_mR(x); 
}
/* ------------------------------------ */
int main(void)
{
	
  fun();

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


Trouver la meilleur équation cubique qui s'ajuste au mieux aux points donnés.


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

 A :
  +1.00   -5.00  +25.00 -125.00 
  +1.00   -2.00   +4.00   -8.00 
  +1.00   +2.00   +4.00   +8.00 
  +1.00   +3.00   +9.00  +27.00 

 b :
  -3.00 
  +0.00 
  +3.00 
  -2.00 

 Ab :
  +1.00   -5.00  +25.00 -125.00   -3.00 
  +1.00   -2.00   +4.00   -8.00   +0.00 
  +1.00   +2.00   +4.00   +8.00   +3.00 
  +1.00   +3.00   +9.00  +27.00   -2.00 

 Press return to continue. 


 -----------------------------------
 Q :
   +0.5000    -0.7028    +0.4900    -0.1265 
   +0.5000    -0.2343    -0.7547    +0.3542 
   +0.5000    +0.3904    -0.1462    -0.7591 
   +0.5000    +0.5466    +0.4110    +0.5313 

 R :
   +2.0000    -1.0000   +21.0000   -49.0000 
   +0.0000    +6.4031   -12.0254  +107.6037 
   +0.0000    -0.0000   +12.3446   -45.2848 
   -0.0000    -0.0000    +0.0000   +21.2539 

 Press return to continue. 


 -----------------------------------
 Q_T :
+5.0000e-01 +5.0000e-01 +5.0000e-01 +5.0000e-01 
-7.0278e-01 -2.3426e-01 +3.9043e-01 +5.4661e-01 
+4.8999e-01 -7.5475e-01 -1.4621e-01 +4.1096e-01 
-1.2651e-01 +3.5423e-01 -7.5907e-01 +5.3135e-01 

 invR :
+5.0000e-01 +7.8087e-02 -7.7450e-01 -8.9281e-01 
+0.0000e+00 +1.5617e-01 +1.5213e-01 -4.6653e-01 
-0.0000e+00 -0.0000e+00 +8.1007e-02 +1.7260e-01 
-0.0000e+00 -0.0000e+00 +0.0000e+00 +4.7050e-02 

 Press return to continue. 


 -----------------------------------
 Solving this system yields a unique
 least squares solution, namely   

 x = invR * Q_T * b :
     +4.43 
     +1.31 
     -0.73 
     -0.14 

 The Cubic equation Curve to Data : 

  s = +4.429 +1.307*t -0.732*t**2 -0.139*t**2

 Press return to continue.