Aller au contenu

Mathc complexes/07g

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"
/* ------------------------------------ */
/* ------------------------------------ */
#define   RA  R3
#define   CA  C3
#define   Cb  C1 
#define   CXY C2
/* ------------------------------------ */
int main(void)
{
double ta[RA*CA]={
/* x**0   x**1    x**2  */
  +1,     +1,     +1,         
  +4,     +2,     +1,         
  +9,     +3,     +1,          
};

double tb[RA*C1]={
/*    y    */
     -9,
     +8,
     -8
};

double xy[RA*CXY] ={1, -9,
                    2,  8,
                    3, -8,   };


double **XY   = ca_A_mRZ(xy,i_mZ(RA,CXY));
double **A    = ca_A_mRZ(ta,i_mZ(RA,CA));
double **b    = ca_A_mRZ(tb,i_mZ(RA,C1));
double **Inv  =             i_mZ(CA,RA);          
double **Invb =             i_mZ(CA,C1);          

  clrscrn();
  printf(" Fitting a linear Curve to Data :\n\n");
  printf("    x     y \n");
  p_mRZ(XY,S5,P0,C6);
  printf(" A :\n x**2   x**1   x**0");
  p_mRZ(A,S6,P2,C7);
  printf(" b :\n y ");
  p_mRZ(b,S6,P2,C7);
  stop();
  
  clrscrn();     
  printf(" Inv : ");
  invgj_mZ(A,Inv); 
  pE_mRZ(Inv,S12,P4,C10);    
 
  printf(" x = Inv * b ");   
  mul_mZ(Inv,b,Invb); 
  p_mRZ(Invb,S10,P4,C10);
  printf("\n The coefficients a, b, c of the curve are :  \n\n" 
         " y = %+.2fx**2  %+.2fx %+.2f\n\n"
            ,Invb[R1][C1],Invb[R2][C1],Invb[R3][C1]);         
  stop();  

  f_mZ(XY);
  f_mZ(b);
  f_mZ(A);
  f_mZ(Inv);
  f_mZ(Invb); 

  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
Exemple de sortie écran :
 Fitting a linear Curve to Data :

    x     y 

   +1    -9 
   +2    +8 
   +3    -8 

 A :
 x**2   x**1   x**0
 +1.00  +1.00  +1.00 
 +4.00  +2.00  +1.00 
 +9.00  +3.00  +1.00 

 b :
 y 
 -9.00 
 +8.00 
 -8.00 

 Press return to continue. 


 Inv : 
 +5.0000e-01  -1.0000e+00  +5.0000e-01 
 -2.5000e+00  +4.0000e+00  -1.5000e+00 
 +3.0000e+00  -3.0000e+00  +1.0000e+00 

 x = Inv * b 
  -16.5000 
  +66.5000 
  -59.0000 


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

 y = -16.50x**2  +66.50x -59.00

 Press return to continue.