Mathc gnuplot/Application : Tangente d'une courbe
Apparence
Préambule
[modifier | modifier le wikicode]La tangente dans Wikipedia.
Présentation
[modifier | modifier le wikicode]N'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.
Dessiner la tangente d'une courbe
[modifier | modifier le wikicode]c01.c Dessiner la tangente d'une courbe |
---|
/* ------------------------------------ */
/* Save as : c01.c */
/* ------------------------------------ */
#include "x_ahfile.h"
#include "fe.h"
/* ------------------------------------ */
int main(void)
{
printf(" Let C be the curve consisting of all"
" ordered pairs (f(t),g(t)).\n\n"
" With\n\n"
" f : t-> %s\n\n"
" g : t-> %s\n\n", feq, geq);
G_Tan( i_WGnuplot(-10.,10.,-5.,5.),
i_time(0,2.*PI,.05),
2.,
f,g,DgDf);
printf(" To see the curve C, open the file \"a_main.plt\""
" with Gnuplot.\n\n"
"\n Press return to continue");
getchar();
return 0;
}
Le résultat.
Résultat dans gnuplot |
---|
Les fichiers h de ce chapitre
[modifier | modifier le wikicode]x_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 "xdef.h"
#include "xplt.h"
/* ------------------------------------ */
#include "kg_tan.h"
fe.h La fonction à dessiner |
---|
/* ------------------------------------ */
/* Save as : fe.h */
/* ------------------------------------ */
double f(
double t)
{
double a=2;
double k1=3;
return( a*sin(k1*t) );
}
char feq[] = "a*sin(k1*t)";
/* ------------------------------------ */
double Df(
double t)
{
double a=2;
double k1=3;
return( a*cos(k1*t)*k1);
}
char Dfeq[] = "a*cos(k1*t)*k1";
/* ------------------------------------ */
double g(
double t)
{
double b =3;
double k2=1;
return( b*cos(k2*t) );
}
char geq[] = "b*cos(k2*t)";
/* ------------------------------------ */
double Dg(
double t)
{
double b =3;
double k2=1;
return( -b*sin(k2*t)*k2 );
}
char Dgeq[] = "-b*sin(k2*t)*k2";
/* ------------------------------------ */
double DgDf(
double t)
{
return(Dg(t)/Df(t));
}
kg_tan.h La fonction graphique |
---|
/* ------------------------------------ */
/* Save as : kg_tan.h */
/* ------------------------------------ */
void G_Tan(
W_Ctrl W,
t_Ctrl T,
double c,
double (*P_f) (double t),
double (*P_g) (double t),
double (*PDgDf)(double t)
)
{
FILE *fp;
double t;
fp = fopen("a_main.plt","w");
fprintf(fp," set zeroaxis\n\n"
" plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
" \"data.plt\" with linesp lt 3 pt 1,\\\n"
" %0.6f*x %+0.6f\n"
" reset",
W.xmini,W.xmaxi,W.ymini,W.ymaxi,
(*PDgDf)(c),
(-(*PDgDf)(c)*(*P_f)(c)+(*P_g)(c)));
fclose(fp);
fp = fopen("data.plt","w");
for(t=T.mini; t<=T.maxi; t+=T.step)
fprintf(fp," %6.6f %6.6f\n",(*P_f)(t),(*P_g)(t));
fclose(fp);
}