Mathc initiation/Fichiers c : c37ca
Installer et compiler ces fichiers dans votre répertoire de travail.
c05a.c |
---|
/* ---------------------------------- */
/* save as c05a.c */
/* ---------------------------------- */
#include "x_hfile.h"
#include "fa.h"
/* ---------------------------------- */
int main(void)
{
double a = 0.;
double b = 1.;
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,1.000]
f : x-> sin(x)
Press return to continue.
Copier ce code dans gnuplot :
set zeroaxis lt 8
set grid
set object rect from 0.58,0 to 0.6,sin(0.6)
plot [0.000:1.000] [0.000:1.000] sin(x)
reset
Exemple de sortie écran :
Draw a typical vertical rectangle on the graph.
The length of the rectangle is : sin(x)
The width of the rectangle is : dx
The Area of the rectangle is : (sin(x)) * dx
Press return to continue.
Exemple de sortie écran :
If we apply
(1.000
int(
(0.000
to : (sin(x)) * dx
We obtain a limit of sums of areas of vertical rectangles.
(1.000
int( (sin(x)) * dx = 0.45970
(0.000
Press return to continue.
Vérifier le résultat avec Octave 5.2 : I = quad (f, a, b)
>> I = quad (@(x) (sin(x)), 0, 1)
I = 0.45970