Mathc gnuplot/Application : Tangente et axes x-y d'une courbe

Un livre de Wikilivres.
Mathc gnuplot
Mathc gnuplot
Mathc gnuplot
Sommaire

I - Dessiner

Fichiers h partagés :

Application :

II - Animer

Application :

III - Géométrie de la tortue standard

Application :

IV - Géométrie de la tortue vectorielle

Application :

Annexe

Livre d'or



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[modifier | modifier le wikicode]

c01.c
Dessiner les points d'intersection de la tangente avec les axes x/y
/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fe.h"
/* ------------------------------------ */
int main(void)
{
double c = PI/2.+.2;

 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);

 printf(" Find at c = %0.3f\n\n"
        " the intersection points of "
        "the tangent with the x-y axis.\n\n\n",c);

 printf(" P(%6.3f, %6.3f) P(c, f(c))\n\n",
        c, f(c));

 printf(" A(%6.3f, 0)     A(f(c)-g(c)/DgDf(c), 0)\n\n",
        f(c)-g(c)/DgDf(c));

 printf(" B( 0, %6.3f)    B(0, g(c)-f(c)*DgDf(c))\n\n\n",
        g(c)-f(c)*DgDf(c));

     G_Tanxy(i_WGnuplot(-10.,10.,-5.,5.),
             i_time(0,2.*PI,.05),
             c,
             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.

Let C be the curve consisting of all ordered pairs (f(t),g(t)).
With
f : t-> a*sin(k1*t)
g : t-> b*cos(k2*t)
.
Find at c = 1.771
the intersection points of the tangent with the x-y axis.
.
P( 1.771, -1.651)     P(c, f(c))
A(-2.337, 0)          A(f(c)-g(c)/DgDf(c), 0)
B( 0, -2.029)         B(0, g(c)-f(c)*DgDf(c))
.
To see the curve C, open the file "a_main.plt" with Gnuplot.
Press return to continue
Résultat dans gnuplot
Tangente17


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_Tanxy(
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 line lt 1,\\\n"
           " %0.6f*x %+0.6f, \\\n"
           " \"p.plt\" lt 1, \\\n"
           " \"px.plt\" lt 1,\\\n"
           " \"py.plt\" lt 1   \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);

        fp = fopen("p.plt","w");
     fprintf(fp," %0.6f   %0.6f", (*P_f)(c), (*P_g)(c)  );
             fclose(fp);

        fp = fopen("px.plt","w");
     fprintf(fp," %0.6f  0.",
             ((*P_f)(c))-((*P_g)(c))/((*PDgDf)(c))      );
             fclose(fp);

        fp = fopen("py.plt","w");
     fprintf(fp," 0.   %0.6f",
             ((*P_g)(c))- (((*PDgDf)(c))*((*P_f)(c)))   );
             fclose(fp);
}