Aller au contenu

Mathc complexes/07n

Un livre de Wikilivres.


Application

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

c00d.c
/* ------------------------------------ */
/*  Save as :   c00d.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA  R5
#define   CA  C5
#define   Cb  C1
 
#define   RXY R3  
#define   CXY C2
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
double xy[RXY*(CXY*C2)] ={
   10,       10,  
   -5,        1,  
    7,      -10,0    };

double ab[RA*((CA+Cb)*C2)]={
/* x**2     y**2     x        y        e    =  +0   */
  +1,      +0,      +0,      +0,      +0,      +1,    
  +0,      +1,      +0,      +0,      +0,      +1,    
+100,    +100,     +10,     +10,      +1,      +0,    
 +25,      +1,      -5,      +1,      +1,      +0,    
 +49,    +100,      +7,     -10,      +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,  of a circle  \n\n");
  printf("     ax**2 + ay**2 + bx + cy + d  = 0            \n\n");
  printf(" that passes through these three XY.         \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,  of a circle  

     ax**2 + ay**2 + bx + cy + d  = 0            

 that passes through these three XY.         

    x     y
  +10   +10 
   -5    +1 
   +7   -10 


 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 
  +0.00   +1.00   +0.00   +0.00   +0.00   +1.00 
+100.00 +100.00  +10.00  +10.00   +1.00   +0.00 
 +25.00   +1.00   -5.00   +1.00   +1.00   +0.00 
 +49.00 +100.00   +7.00  -10.00   +1.00   +0.00 

 Press return to continue. 


 A_T :
     +1.00      +0.00    +100.00     +25.00     +49.00 
     +0.00      +1.00    +100.00      +1.00    +100.00 
     +0.00      +0.00     +10.00      -5.00      +7.00 
     +0.00      +0.00     +10.00      +1.00     -10.00 
     +0.00      +0.00      +1.00      +1.00      +1.00 

 A_TA :
 +13027.00  +14925.00   +1218.00    +535.00    +174.00 
 +14925.00  +20002.00   +1695.00      +1.00    +201.00 
  +1218.00   +1695.00    +174.00     +25.00     +12.00 
   +535.00      +1.00     +25.00    +201.00      +1.00 
   +174.00    +201.00     +12.00      +1.00      +3.00 

 Press return to continue. 


 inv(A_TA) :
   +1.0000    -0.0000    -3.8132    -1.9780   -42.0879 
   -0.0000    +1.0000    -7.2527    +1.0879   -38.3516 
   -3.8132    -7.2527   +67.1508    -0.3486  +438.6119 
   -1.9780    +1.0879    -0.3486    +5.1012   +41.5293 
  -42.0879   -38.3516  +438.6119   +41.5293 +3242.7022 

 inv(A_TA)*A_T :
   +1.0000    +0.0000    +0.0000    +0.0000    +0.0000 
   +0.0000    +1.0000    +0.0000    -0.0000    +0.0000 
   -3.8132    -7.2527    +0.0403    -0.0733    +0.0330 
   -1.9780    +1.0879    +0.0440    +0.0110    -0.0549 
  -42.0879   -38.3516    +0.1575    +0.6227    +0.2198 


 x = inv(A_TA)*A_T*b :
   +1.0000 
   +1.0000 
  -11.0659 
   -0.8901 
  -80.4396 

 Press return to continue. 


 x = inv(A_TA)*A_T*b :
     +1.00 
     +1.00 
    -11.07 
     -0.89 
    -80.44 

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

  +1.00x**2 +1.00y**2 -11.07x -0.89y -80.44 = 0

 Press return to continue.