Aller au contenu

Mathc complexes/07q

Un livre de Wikilivres.


Application

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

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

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

double **XY =  ca_A_mRZ(xy,i_mZ(RXY,CXY));

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, 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("\n");
  printf(" Using the given XY, we obtain this matrix.\n");
  printf("  (a = 1. This is my choice)\n\n");
  printf("   x**2    y**2    x       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(" The coefficients a, b, c, d, e, of the curve are : \n\n"
         "  %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\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, d, e, of the curve 

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

 that passes through these four points.

    x     y
   +1    -8 
   +2    +2 
   +3    +1 
   +4    +2 


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

   x**2    y**2    x       y      
  +1.00   +0.00   +0.00   +0.00   +0.00   +1.00 
  +1.00  +64.00   +1.00   -8.00   +1.00   +0.00 
  +4.00   +4.00   +2.00   +2.00   +1.00   +0.00 
  +9.00   +1.00   +3.00   +1.00   +1.00   +0.00 
 +16.00   +4.00   +4.00   +2.00   +1.00   +0.00 

 Press return to continue. 


 A_T :
     +1.00      +1.00      +4.00      +9.00     +16.00 
     +0.00     +64.00      +4.00      +1.00      +4.00 
     +0.00      +1.00      +2.00      +3.00      +4.00 
     +0.00      -8.00      +2.00      +1.00      +2.00 
     +0.00      +1.00      +1.00      +1.00      +1.00 

 A_TA :
   +355.00    +153.00    +100.00     +41.00     +30.00 
   +153.00   +4129.00     +91.00    -495.00     +73.00 
   +100.00     +91.00     +30.00      +7.00     +10.00 
    +41.00    -495.00      +7.00     +73.00      -3.00 
    +30.00     +73.00     +10.00      -3.00      +4.00 

 Press return to continue. 


 inv(A_TA) :
   +1.0000    -0.1444    -6.0000    -0.5667    +9.7111 
   -0.1444    +0.0386    +0.8778    +0.1898    -1.6728 
   -6.0000    +0.8778   +36.5000    +3.3667   -59.7444 
   -0.5667    +0.1898    +3.3667    +1.0139    -6.8704 
   +9.7111    -1.6728   -59.7444    -6.8704  +102.1543 

 inv(A_TA)*A_T :
   +1.0000    +0.0000    -0.0000    -0.0000    -0.0000 
   -0.1444    +0.0111    +0.0389    -0.1111    +0.0611 
   -6.0000    -0.0000    -0.5000    -0.0000    +0.5000 
   -0.5667    -0.0333    +0.3833    -0.6667    +0.3167 
   +9.7111    +0.0222    +1.0778    +1.7778    -1.8778 


 x = inv(A_TA)*A_T*b :
   +1.0000 
   -0.1444 
   -6.0000 
   -0.5667 
   +9.7111 

 Press return to continue. 


 x = inv(A_TA)*A_T*b :
     +1.00 
     -0.14 
     -6.00 
     -0.57 
     +9.71 

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

  +1.00x**2 -0.14y**2 -6.00x -0.57y +9.71 = 0

 Press return to continue.