Aller au contenu

Mathc initiation/Fichiers h : x 18c01b

Un livre de Wikilivres.


Sommaire



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

c01b.c
/* ---------------------------------- */
/* save as c01b.c                     */
/* ---------------------------------- */
#include "x_a.h"
/* ---------------------------------- */
# define   DEGREE     5
# define   COEFF_NB   DEGREE + 1
/* ---------------------------------- */
int main(void)
{
double k =     1;
double remainder;

double *Pa  = I_Px( COEFF_NB);
double *Pt  = I_Px( COEFF_NB);
double *Pqr = I_Px( COEFF_NB);
double *Pq  = I_Px((COEFF_NB-1));

double a[COEFF_NB] = {3,0,-38,5,0,-1};

 clrscrn();
 
 c_a_Px(a,Pa);
 printf("\n If P(x) is : \n\n ");
 p_Px(Pa);printf(" = 0\n\n");

 printf(" If we divide P(x) by : [x-(%+.0f)] \n\n",k);
 remainder = compute_horner(k,Pa,Pt,Pqr,Pq);
 p_horner(Pa,Pt,Pqr);printf("\n");

 printf(" The synthetic division indicates that the result is :\n\n S = [");
 p_Px(Pq);printf("] %+.0f/[x-(%+.0f)]\n\n\n", remainder,k); 

 printf(" The synthetic division indicates that P(%+.0f) = %+.0f\n\n\n",
        k, remainder);
        
 stop();
 
 free(Pa);
 free(Pt);
 free(Pqr);
 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(x) is : 

 +3x**5 -38x**3 +5x**2 -1 = 0

 If we divide P(x) by : [x-(+1)] 

      +3      +0     -38      +5      +0      -1   
      +0      +3      +3     -35     -30     -30   
   ------------------------------------------------
      +3      +3     -35     -30     -30     -31   


 The synthetic division indicates that the result is :

 S = [+3x**4 +3x**3 -35x**2 -30x -30] -31/[x-(+1)]


 The synthetic division indicates that P(+1) = -31


 Press return to continue.


Fichier de commande gnuplot :
# ---------------------
# Copy and past this file into the screen of gnuplot
#
#
set zeroaxis lt 3 lw 1
plot [-5.:5.] [-10.:10.]\
    +3.00*x**5  -38.00*x**3  +5.00*x**2  -1.00
reset
# ---------------------