Aller au contenu

Mathc complexes/07y

Un livre de Wikilivres.


Application

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

c00f.c
/* ------------------------------------ */
/*  Save as :   c00f.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R5
#define   CA C5
#define   Cb C1 

#define   RXY R5  
#define   CXY C2 
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double   xy[RXY*CXY] ={
  1,   -2,
  2,   -2,
  3,    3,
  4,   -9,
  5,    4      };

double ab[RA*(CA+Cb)]={
/* x**4    x**3    x**2    x**1    x**0    y   */
  +1,   +1,   +1,   +1,   +1,   -2, 
 +16,   +8,   +4,   +2,   +1,   -2, 
 +81,  +27,   +9,   +3,   +1,   +3, 
+256,  +64,  +16,   +4,   +1,   -9, 
+625, +125,  +25,   +5,   +1,   +4,    
};

double **XY =  ca_A_mRZ(xy,i_mZ(RA,C2));

double **Ab =  ca_A_mRZ(ab,i_Abr_Ac_bc_mZ(RA,CA,Cb));
double **A  = c_Ab_A_mZ(Ab,i_mZ(RA,CA));
double **b  = c_Ab_b_mZ(Ab,i_mZ(RA,Cb));

double **A_T        = i_mZ(CA,RA);
double **A_TA       = i_mZ(CA,CA); //         A_T*A
double **invA_TA    = i_mZ(CA,CA); //     inv(A_T*A)
double **invA_TAA_T = i_mZ(CA,RA); //     inv(A_T*A)*A_T

double **x          = i_mZ(CA,Cb); // x = inv(A_T*A)*A_T*b

  clrscrn();
  printf("\n");
  printf(" Find the coefficients a, b, c  of the curve \n\n");
  printf("   y =  ax**4 + bx**3 + cx**2 + dx + e       \n\n");
  printf(" that passes through the points.             \n\n");
  
  printf("    x     y");
  p_mRZ(XY,S5,P0,C6);
  printf("\n");
  printf(" Using the given points, we obtain this matrix.\n");
  printf("   x**4    x**3    x**2    x**1    x**0    y");
  p_mRZ(Ab,S7,P2,C6);
  stop();

  
  clrscrn();
  printf(" A_T :");
  p_mRZ(transpose_mZ(A,A_T),S10,P2,C7);
  printf(" A_TA :");
  p_mRZ(mul_mZ(A_T,A,A_TA),S10,P2,C7);
  stop();
  
  clrscrn();
  printf(" inv(A_TA) :");
  p_mRZ(inv_mZ(A_TA,invA_TA),S10,P4,C7);  
  printf(" inv(A_TA)*A_T :");
  p_mRZ(mul_mZ(invA_TA,A_T,invA_TAA_T),S10,P4,C7);
  printf("\n x = inv(A_TA)*A_T*b :");
  p_mRZ(mul_mZ(invA_TAA_T,b,x),S10,P4,C7);
  stop();
  
  clrscrn();
  printf("\n x = inv(A_TA)*A_T*b :");
  p_mRZ(x,S10,P2,C7); 
  printf("\n The coefficients a, b, c of the curve are :  \n\n" 
         " y = %+.2fx**4 %+.2fx**3 %+.2fx**2  %+.2fx %+.2f\n\n"
            ,x[R1][C1],x[R2][C1],x[R3][C1],x[R4][C1],x[R5][C1]);       
  stop();  

  f_mZ(XY);  
  f_mZ(A);
  f_mZ(b);
  f_mZ(Ab);

  f_mZ(A_T);
  f_mZ(A_TA);       //         A_T*A
  f_mZ(invA_TA);    //     inv(A_T*A)
  f_mZ(invA_TAA_T); //     inv(A_T*A)*A_T
    
  f_mZ(x); 

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Exemple de sortie écran :
  Find the coefficients a, b, c  of the curve 

   y =  ax**4 + bx**3 + cx**2 + dx + e       

 that passes through the points.             

    x     y
   +1    -2 
   +2    -2 
   +3    +3 
   +4    -9 
   +5    +4 


 Using the given points, we obtain this matrix.
   x**4    x**3    x**2    x**1    x**0    y
  +1.00   +1.00   +1.00   +1.00   +1.00   -2.00 
 +16.00   +8.00   +4.00   +2.00   +1.00   -2.00 
 +81.00  +27.00   +9.00   +3.00   +1.00   +3.00 
+256.00  +64.00  +16.00   +4.00   +1.00   -9.00 
+625.00 +125.00  +25.00   +5.00   +1.00   +4.00 

 Press return to continue. 


 A_T :
     +1.00     +16.00     +81.00    +256.00    +625.00 
     +1.00      +8.00     +27.00     +64.00    +125.00 
     +1.00      +4.00      +9.00     +16.00     +25.00 
     +1.00      +2.00      +3.00      +4.00      +5.00 
     +1.00      +1.00      +1.00      +1.00      +1.00 

 A_TA :
+462979.00  +96825.00  +20515.00   +4425.00    +979.00 
 +96825.00  +20515.00   +4425.00    +979.00    +225.00 
 +20515.00   +4425.00    +979.00    +225.00     +55.00 
  +4425.00    +979.00    +225.00     +55.00     +15.00 
   +979.00    +225.00     +55.00     +15.00      +5.00 

 Press return to continue. 


 inv(A_TA) :
   +0.1215    -1.4583    +6.0243    -9.8958    +5.2500 
   -1.4583   +17.5694   -72.9167  +120.3889   -64.1667 
   +6.0243   -72.9167  +304.3299  -505.7292  +271.2500 
   -9.8958  +120.3889  -505.7292  +847.1528  -458.3333 
   +5.2500   -64.1667  +271.2500  -458.3333  +251.0000 

 inv(A_TA)*A_T :
   +0.0417    -0.1667    +0.2500    -0.1667    +0.0417 
   -0.5833    +2.1667    -3.0000    +1.8333    -0.4167 
   +2.9583    -9.8333   +12.2500    -6.8333    +1.4583 
   -6.4167   +17.8333   -19.5000   +10.1667    -2.0833 
   +5.0000   -10.0000   +10.0000    -5.0000    +1.0000 


 x = inv(A_TA)*A_T*b :
   +2.6667 
  -30.3333 
 +117.8333 
 -181.1667 
  +89.0000 

 Press return to continue. 


 x = inv(A_TA)*A_T*b :
     +2.67 
    -30.33 
   +117.83 
   -181.17 
    +89.00 


 The coefficients a, b, c of the curve are :  

 y = +2.67x**4 -30.33x**3 +117.83x**2  -181.17x +89.00

 Press return to continue.