Aller au contenu

Mathc complexes/06i

Un livre de Wikilivres.


Application

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

c00b.c
/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "w_a.h" 
#include   "d.h"
/* ------------------------------------ */
#define   RA R5
#define   CA C5
#define   Cb C1 
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double   xy[R4*(C2*C2)] ={
   1,      1,
   2,      4,
   3,      9,
   4,     16  };

   
double ab[RA*(CA+Cb)]={
/* x**2   y**2    x       y        e   =  +0   */
  +1,   +0,   +0,   +0,   +0,   +1, 
  +1,   +1,   +1,   +1,   +1,   +0, 
  +4,  +16,   +2,   +4,   +1,   +0, 
  +9,  +81,   +3,   +9,   +1,   +0, 
 +16, +256,   +4,  +16,   +1,   +0
};

double **XY = ca_A_mRZ(xy,i_mZ(R4,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 **Q    = i_mZ(RA,CA);
double **R    = i_mZ(CA,CA);

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


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

  clrscrn();
  printf("\n");
  printf(" Find the coefficients a, b, c, d, e, of the curve \n\n");
  printf("     ax**2 + by**2 + cx + dy + e  = 0 \n\n");
  printf(" that passes through these four points.\n\n");
  printf("    x     y");
  p_mRZ(XY,S5,P0,C6);
  printf(" Using the given points, we obtain this matrix.\n");
  printf("  (a = 1. This is my choice)\n\n");  
  printf(" Ab :\n");
  printf("   x**2    y**2    x       y       e    =  0     ");
  p_mRZ(Ab,S7,P2,C6);
  stop();

    
  clrscrn();
  QR_mZ(A,Q,R);    
  printf(" Q :");
  p_mRZ(Q,S10,P4,C6); 
  printf(" R :");
  p_mRZ(R,S10,P4,C6);
  stop();

  clrscrn();
  transpose_mZ(Q,Q_T);   
  printf(" Q_T :");
  pE_mRZ(Q_T,S12,P4,C6); 
  inv_mZ(R,invR); 
  printf(" invR :");
  pE_mRZ(invR,S12,P4,C6);
  stop();
  
  clrscrn();
  printf(" Solving this system yields a unique\n"
         " least squares solution, namely   \n\n");
  mul_mZ(invR,Q_T,invR_Q_T);
  mul_mZ(invR_Q_T,b,x);
  printf(" x = invR * Q_T * b :");
  p_mRZ(x,S10,P2,C6);
  printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
         "  %+.2fx**2  %+.2fy  = 0\n\n"
            ,x[R1][C1],x[R4][C1]);  
  
  stop();

  f_mZ(XY);  
  f_mZ(A);
  f_mZ(b);
  f_mZ(Ab);
  f_mZ(Q);
  f_mZ(Q_T);
  f_mZ(R);
  f_mZ(invR);  
  f_mZ(invR_Q_T); 
  f_mZ(x); 

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

     ax**2 + by**2 + cx + dy + e  = 0 

 that passes through these four points.

    x     y
   +1    +1 
   +2    +4 
   +3    +9 
   +4   +16 

 Using the given points, we obtain this matrix.
  (a = 1. This is my choice)

 Ab :
   x**2    y**2    x       y       e    =  0     
  +1.00   +0.00   +0.00   +0.00   +0.00   +1.00 
  +1.00   +1.00   +1.00   +1.00   +1.00   +0.00 
  +4.00  +16.00   +2.00   +4.00   +1.00   +0.00 
  +9.00  +81.00   +3.00   +9.00   +1.00   +0.00 
 +16.00 +256.00   +4.00  +16.00   +1.00   +0.00 

 Press return to continue. 


 Q :
   +0.0531    -0.1949    -0.6241    -0.7548    +0.0000 
   +0.0531    -0.1807    +0.6555    -0.4915    +0.5415 
   +0.2123    -0.5532    +0.3364    -0.1204    -0.7220 
   +0.4777    -0.6080    -0.2539    +0.4005    +0.4212 
   +0.8492    +0.5037    +0.0568    -0.1173    -0.0902 

 R :
  +18.8414  +259.5343    +5.3074   +18.7884    +1.5922 
   +0.0000   +70.6822    -1.0960    +0.1949    -0.8381 
   -0.0000    -0.0000    +0.7936    +0.6241    +0.7948 
   +0.0000    +0.0000    +0.0000    +0.7548    -0.3287 
   +0.0000    +0.0000    +0.0000    +0.0000    +0.1504 

 Press return to continue. 


 Q_T :
 +5.3074e-02  +5.3074e-02  +2.1230e-01  +4.7767e-01  +8.4919e-01 
 -1.9488e-01  -1.8073e-01  -5.5316e-01  -6.0796e-01  +5.0374e-01 
 -6.2405e-01  +6.5551e-01  +3.3642e-01  -2.5391e-01  +5.6750e-02 
 -7.5483e-01  -4.9155e-01  -1.2040e-01  +4.0047e-01  -1.1727e-01 
 +3.1185e-14  +5.4149e-01  -7.2199e-01  +4.2116e-01  -9.0249e-02 

 invR :
 +5.3074e-02  -1.9488e-01  -6.2405e-01  -7.5483e-01  +0.0000e+00 
 +0.0000e+00  +1.4148e-02  +1.9537e-02  -1.9805e-02  -6.7686e-02 
 +0.0000e+00  -0.0000e+00  +1.2600e+00  -1.0417e+00  -8.9346e+00 
 -0.0000e+00  +0.0000e+00  -0.0000e+00  +1.3248e+00  +2.8955e+00 
 +0.0000e+00  +0.0000e+00  +0.0000e+00  -0.0000e+00  +6.6483e+00 

 Press return to continue. 


 Solving this system yields a unique
 least squares solution, namely   

 x = invR * Q_T * b :
     +1.00 
     -0.00 
     +0.00 
     -1.00 
     +0.00 

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

  +1.00x**2  -1.00y  = 0

 Press return to continue.