Mathc initiation/Fichiers c : c37cc

Un livre de Wikilivres.


Sommaire


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

c05c.c
/* ---------------------------------- */
/* save as c05c.c                     */
/* ---------------------------------- */
#include "x_hfile.h"
#include      "fc.h"
/* ---------------------------------- */
int main(void)
{
double   a =   0.;
double   b =   5.;
double   n = 2*5.;
 
 clrscrn();
 printf(" Verify with a software that f(x) >= 0 on [%.3f,%.3f]\n\n", a, b);
 printf(" f : x-> %s\n\n\n\n", feq);
 stop();

 clrscrn();
 printf(" Draw a typical vertical rectangle on the graph.\n\n\n\n");

 printf(" The length of the rectangle is :   %s       \n", feq);
 printf(" The width  of the rectangle is :    dx    \n\n"     );
 printf(" The Area   of the rectangle is :   (%s) * dx\n", feq);
 printf(" \n\n\n\n\n");
 stop();

 clrscrn();
 printf(" If we apply \n\n\n");
 printf("    (%.3f\n",     b);
 printf(" int(      \n");
 printf("    (%.3f\n\n\n", a);

 printf(" to  : (%s) * dx\n\n\n", feq);
 printf(" We obtain a limit of sums of areas of vertical rectangles.\n\n\n");

 printf("    (%.3f\n",     b);
 printf(" int(      (%s) * dx = %.5f\n", feq, simpson(f,a,b,n));
 printf("    (%.3f\n\n\n", a);

 stop();

 return 0;
}
/* ---------------------------------- */


Vous trouverez ci-dessous le code Gnuplot pour dessiner la fonction et un rectangle caractèristique. Ainsi que le code pour Octave pour vérifier le calcul.


Exemple de sortie écran :

 Verify with a software that f(x) >= 0 on [0.000,5.000]

 f : x-> exp(x)



 Press return to continue.


Copier ce code dans gnuplot :

 set zeroaxis lt 8
 set grid
 set object rect from 4,0 to 4.3,exp(4.3)
 plot [0.000:5.000] [0.000:150.0] exp(x)
 reset


Exemple de sortie écran :

 Draw a typical vertical rectangle on the graph.



 The length of the rectangle is :   exp(x)       
 The width  of the rectangle is :    dx    

 The Area   of the rectangle is :   (exp(x)) * dx
 




 Press return to continue.


Exemple de sortie écran :

 If we apply 


    (5.000
 int(      
    (0.000


 to  : (exp(x)) * dx


 We obtain a limit of sums of areas of vertical rectangles.


    (5.000
 int(      (exp(x)) * dx = 147.46286
    (0.000


 Press return to continue.


Vérifier le résultat avec Octave 5.2 :

I = quad (f, a, b) 
>> I = quad (@(x) (exp(x)), 0, 5)
I =  147.41