Aller au contenu

Mathc matrices/c25o

Un livre de Wikilivres.


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


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


c01g.c
/* ------------------------------------ */
/*  Save as :   c01g.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA R5
#define   CA C5
/* ------------------------------------ */
#define FACTOR_E        +1.E-0         
/* ------------------------------------ */
void fun(void)
{
double   xy[8] ={
   1,      0,
   2,      3,
   3,      4,
   4,      0   };
   
double tA[RA*CA]={
/* x**2     y**2     x        y        e     */
  +1.00,   +0.00,   +0.00,   +0.00,   +0.00,
  +1.00,   +0.00,   +1.00,   +0.00,   +1.00,
  +4.00,   +9.00,   +2.00,   +3.00,   +1.00,   
  +9.00,  +16.00,   +3.00,   +4.00,   +1.00,
 +16.00,   +0.00,   +4.00,   +0.00,   +1.00
};

double tb[RA*C1]={
/* = 0   */
  +1.00, 
  +0.00, 
  +0.00, 
  +0.00, 
  +0.00, 
};

double **XY      = ca_A_mR(xy,i_mR(RA,C2));
double **A       = ca_A_mR(tA,i_mR(RA,CA));
double **b       = ca_A_mR(tb,i_mR(RA,C1));
double **Pinv    = i_mR(CA,RA);         
double **Pinvb   = i_mR(CA,C1);         

  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_mR(XY,S10,P0,C6);
  stop();
  
  clrscrn();
  printf(" Using the given points, we obtain this matrix.\n");
  printf("  (a = 1. This is my choice)\n\n");  
  printf(" A :");
  p_mR(A,S10,P2,C7);
  printf(" b :");
  p_mR(b,S10,P2,C7);
   
  printf(" Pinv = V * invS_T * U_T ");
  pseudo_Rn_mR(A,Pinv,FACTOR_E); 
  pE_mR(Pinv,S12,P4,C10); 
  stop();
  
  clrscrn();
  printf(" Solving this system yields a unique\n"
         " least squares solution, namely   \n\n");  
  printf(" x = Pinv * b ");   
  mul_mR(Pinv,b,Pinvb); 
  p_mR(Pinvb,S10,P4,C10);
  printf(" The coefficients a, b, c, d, e, of the curve are : \n\n"
         "  %+.2fx**2 %+.2fy**2 %+.2fx %+.2fy %+.2f = 0\n\n"
            ,Pinvb[R1][C1],Pinvb[R2][C1],Pinvb[R3][C1],
             Pinvb[R4][C1],Pinvb[R5][C1]);      
  stop();  

  f_mR(XY);
  f_mR(b);
  f_mR(A);
  f_mR(Pinv);
  f_mR(Pinvb); 
}
/* ------------------------------------ */
int main(void)
{
  
  fun();

  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         +0 
        +2         +3 
        +3         +4 
        +4         +0 
        +1         +0 

 Press return to continue. 


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

 A :
     +1.00      +0.00      +0.00      +0.00      +0.00 
     +1.00      +0.00      +1.00      +0.00      +1.00 
     +4.00      +9.00      +2.00      +3.00      +1.00 
     +9.00     +16.00      +3.00      +4.00      +1.00 
    +16.00      +0.00      +4.00      +0.00      +1.00 

 b :
     +1.00 
     +0.00 
     +0.00 
     +0.00 
     +0.00 


 Press return to continue. 


 -----------------------------------
 Pinv = V * invS_T * U_T 
   +1.0000    +0.0000    -0.0000    +0.0000    -0.0000 
   -0.1667    +0.1389    -0.3333    +0.2500    -0.0556 
   -5.0000    -0.3333    +0.0000    -0.0000    +0.3333 
   +1.1667    -0.6389    +1.3333    -0.7500    +0.0556 
   +4.0000    +1.3333    -0.0000    +0.0000    -0.3333 

 Press return to continue. 


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

 x = Pinv * b 
   +1.0000 
   -0.1667 
   -5.0000 
   +1.1667 
   +4.0000 

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

  +1.00x**2 -0.17y**2 -5.00x +1.17y +4.00 = 0

 Press return to continue.