Mathc gnuplot/Animation : Tangente
La tangente dans Wikipedia.
Préambule
modifierVoir l'introduction pour créer une animation avec gnuplot sous windows ou linux.
Présentation
modifierN'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.
Animer la tangente
modifierNous utilisons ici la méthode avec la commande "pause 1" de gnuplot.
c01.c Animer la tangente |
---|
/* ------------------------------------ */
/* Save as : c01.c */
/* ------------------------------------ */
#include "x_ahfile.h"
#include "f2.h"
/* ------------------------------------ */
int main(void)
{
printf(" f : x-> %s \n", feq);
printf(" f': x-> %s\n\n",Dfeq);
printf(" The equation of the tangent is : \n\n");
printf(" y = f'(c) (x-c) + f(c) \n\n");
G_TanA(i_WGnuplot(-7, 7,-2,2),
i_time(-1.5,2,.2),
feq,
f,
Df);
printf(" load \"a_main.plt\" with gnuplot. \n\n"
" Press return to continue");
getchar();
return 0;
}
Le résultat dans a_main.plt
# Gnuplot file : load "a_main.plt"
set zeroaxis
plot [-7.000:7.000] [-2.000:2.000] cos(x), 0.997495*x +1.566980
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), 0.963558*x +1.520124
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), 0.891207*x +1.433924
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), 0.783327*x +1.326604
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), 0.644218*x +1.215795
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), 0.479426*x +1.117295
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), 0.295520*x +1.043993
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), 0.099833*x +1.004988
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.099833*x +1.004988
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.295520*x +1.043993
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.479426*x +1.117295
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.644218*x +1.215795
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.783327*x +1.326604
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.891207*x +1.433924
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.963558*x +1.520124
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.997495*x +1.566980
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.991665*x +1.556986
pause 1
plot [-7.000:7.000] [-2.000:2.000] cos(x), -0.946300*x +1.474681
pause 1
reset
Les fichiers h de ce chapitre
modifierx_ahfile.h Appel des fichiers |
---|
/* ------------------------------------ */
/* Save as : x_ahfile.h */
/* ------------------------------------ */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <string.h>
/* ------------------------------------ */
#include "xplt.h"
/* ------------------------------------ */
#include "kg_tan.h"
f2.h La fonction à dessiner |
---|
/* ------------------------------------ */
/* Save as : f2.h */
/* ----------- f ---------------------- */
double f(
double x)
{
return( cos(x));
}
char feq[] = " cos(x)";
/* ------------ f' --------------------- */
double Df(
double x)
{
return( (-sin(x)) );
}
char Dfeq[] = " (-sin(x)) ";
kg_tan.h La fonction graphique |
---|
/* ------------------------------------ */
/* Save as : kg_tan.h */
/* ------------------------------------
y = ax + b [P(xp,yp);(y-yp)=a(x-xp)]
a = f'(x)
b = y - ax
b = y - f'(x)x
b = f(x) - f'(x)x
x=p
a = f'(p)
b = f(p) - f'(p)p
------------------------------------ */
void G_TanA(
W_Ctrl w,
t_Ctrl Pic,
char fEQ[],
double (*P_f)(double x),
double (*PDf)(double x)
)
{
FILE *fp = fopen("a_main.plt","w");
double p = Pic.mini;
fprintf(fp,"# Gnuplot file : load \"a_main.plt\"\n"
" set zeroaxis\n"
" reset\n\n");
for(;p<Pic.maxi;p+=Pic.step)
fprintf(fp," plot [%0.3f:%0.3f] [%0.3f:%0.3f] "
"%s, "
" %0.6f*x %+0.6f \n"
" pause 1\n\n",
w.xmini,w.xmaxi,w.ymini,w.ymaxi,
fEQ,
(*PDf)(p), (-(*PDf)(p)*p+(*P_f)(p)) );
fprintf(fp," reset");
fclose(fp);
}