Mathc initiation/Fichiers c : c37cb

Un livre de Wikilivres.


Sommaire


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

c05b.c
/* ---------------------------------- */
/* save as c05b.c                     */
/* ---------------------------------- */
#include "x_hfile.h"
#include      "fb.h"
/* ---------------------------------- */
int main(void)
{
double   a =   1.;
double   b =   3.;
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 [1.000,3.000]

 f : x-> log(x)



 Press return to continue.


Copier ce code dans gnuplot :

 set zeroaxis lt 8
 set grid
 set object rect from 2.5,0 to 2.6,log(2.6)
 plot [1.000:3.000] [0.000:1.200] log(x)
 reset


Exemple de sortie écran :

 Draw a typical vertical rectangle on the graph.



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

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




 Press return to continue.


Exemple de sortie écran :

 If we apply 


    (3.000
 int(      
    (1.000


 to  : (log(x)) * dx


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


    (3.000
 int(      (log(x)) * dx = 1.29582
    (1.000


 Press return to continue.
Vérifier le résultat avec Octave 5.2 :

I = quad (f, a, b) 
>> I = quad (@(x) (log(x)), 1, 3)
I =  1.2958