Sommaire



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

c01c.c
'
/* ---------------------------------- */
/* save as c01c.c                     */
/* ---------------------------------- */
#include "x_hfile.h"
/* ---------------------------------- */
# define   DEGREE  6
# define   COEFF   DEGREE + 1
/* ---------------------------------- */
int main(void)
{
int    n = COEFF;
double x =  1;
double remainder;

double *Px = I_p(n);
double *Pt = I_p(n);
double *Pa = I_p(n);
double *Pq = I_p((n-1));

double a[COEFF]={5,3,-2,6,5,-2,-9};

 clrscrn();
 c_a_P(a,Px);
 printf("\n If P(x) is : \n\n");
 p_P(Px);

 printf(" If we divide P(x) by : x - (%+.3f) \n\n",x);
 remainder = compute_horner(x,Px,Pt,Pa,Pq);
 p_horner(Px,Pt,Pa);

 printf(" The synthetic division indicates that the quotien is :\n\n");
 p_P(Pq );

 printf(" The synthetic division indicates that P(%+.3f) = %+.3f\n\n",
        x, remainder);
        
 stop();
 
 free(Px);
 free(Pt);
 free(Pa);
 free(Pq);

 return 0;
}


Vérifier les calculs à la main. (Voir le premier exemple pour apprendre la méthode de Horner)


Exemple de sortie écran :

 If p_A is : 

   +5.00*x**6  +3.00*x**5  -2.00*x**4  +6.00*x**3  +5.00*x**2  -2.00*x  -9.00  


 If we divide p_A by : x - (+1.000) 


     +5.00     +3.00     -2.00     +6.00     +5.00     -2.00     -9.00   
     +0.00     +5.00     +8.00     +6.00    +12.00    +17.00    +15.00   
   ----------------------------------------------------------------------
     +5.00     +8.00     +6.00    +12.00    +17.00    +15.00     +6.00   


 The synthetic division indicates that the quotien is :

   +5.00*x**5  +8.00*x**4  +6.00*x**3  +12.00*x**2  +17.00*x  +15.00  


 The synthetic division indicates that p_A(+1.000) = +6.000

 Press return to continue.
Cet article est issu de Wikibooks. Le texte est sous licence Creative Commons - Attribution - Partage dans les Mêmes. Des conditions supplémentaires peuvent s'appliquer aux fichiers multimédias.