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

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

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

double a[COEFF]={2,1,0,-3600};

 clrscrn();
 
 x = 3.;
 c_a_P(a,Px);
 printf("\n If P(x) is : \n\n");
 p_P(Px);
 
 printf(" Find an upper bound for the zeros of P(x).\n\n");
 printf(" If we divide P(x) by : x - (%+.2f)\n\n",x);
 compute_horner(x,Px,Pt,Pa,Pq);
 p_horner(Px,Pt,Pa);
 
 printf(" The third row have some negative numbers\n\n");
 printf(" So %+.3f is not an upper bound for the zeros of P(x)\n\n",x);
 stop();

 clrscrn();
 
 x = 13.;
 printf(" If we divide P(x) by : x - (%+.2f)\n\n",x);
 compute_horner(x,Px,Pt,Pa,Pq);
 p_horner(Px,Pt,Pa);
 
 printf(" The third row are nonnegative numbers.\n\n");
 printf(" So %+.2f is an upper bound for the zeros of P(x).\n\n",x);

 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 : 

   +2.00*x**3  + x**2  -3600.00  


 Find an upper bound for the zeros of p_A.

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


     +2.00     +1.00     +0.00   -3600.00   
     +0.00     +6.00    +21.00    +63.00   
   ----------------------------------------
     +2.00     +7.00    +21.00   -3537.00   


 The third row have some negative numbers

 So +3.000 is not an upper bound for the zeros of p_A

 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.