Mathc gnuplot/Application : Tangente et axes x-y

Un livre de Wikilivres.
Aller à : navigation, rechercher
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 :

Conclusion

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]

Crystal Clear mimetype source c.png c01.c
Dessiner les points d'intersection de la tangente avec les axes x/y
/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
double c = 1;

 printf("  f : x-> %s  \n", feq);
 printf(" Df : x-> %s\n\n",Dfeq);

 printf(" With c = %0.3f, the equation of"
           " the tangent is :\n\n"
           "      y =  Df(c) (x-c) + f(c) = ",c);
eq_Tan(c,f,Df);

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

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

 printf(" A(%5.3f, 0.000)     A(c-f(c)/Df(c), 0)\n",
        c-(f(c))/(Df(c)));

 printf(" B(    0, %5.3f)     B(0, f(c)-c Df(c))\n",
        f(c)-((Df(c))*c));

 G_Tan_xy(i_WGnuplot(-7,7,-2,2),
          c,
          feq,
          f,Df);

 printf(" load \"a_main.plt\" with gnuplot. \n\n"
        " Press return to continue");
 getchar();

 return 0;
}

Le résultat.

 f : x->  cos(x)  
Df : x->  (-sin(x)) 
.
With c = 1.000, the equation of the tangent is :
.
     y =  Df(c) (x-c) + f(c) =  -0.841*x +1.382
.
.
Find at c = 1.000
.
the intersection points of the tangent with the x-y axis.
.
P(1.000, 0.540)     P(c, f(c))
A(1.642, 0.000)     A(c-f(c)/Df(c), 0)
B(    0, 1.382)     B(0, f(c)-c Df(c))
.
load "a_main.plt" with gnuplot.
Résultat dans gnuplot
Tangente03


Les fichiers h de ce chapitre[modifier | modifier le wikicode]

Crystal Clear mimetype source h.png 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     "xplt.h"
/* ------------------------------------ */
#include   "kg_tan.h"
#include    "k_tan.h"


Crystal Clear mimetype source h.png 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)) ";


Crystal Clear mimetype source h.png k_tan.h
Equation de la tangente
/* ------------------------------------ */
/*  Save as :    k_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=c
   a = f'(c)
   b = f(c) - f'(c)c
   ------------------------------------ */
void eq_Tan(
double    c,
double (*P_f)(double x),
double (*PDf)(double x)
)
{
 printf(" %0.3f*x %+0.3f\n\n\n", 
 (*PDf)(c), (*P_f)(c) - (*PDf)(c)*c );
}
/* ------------------------------------ */
void eq_Tanf(
FILE *fp,
double    c,
double (*P_f)(double x),
double (*PDf)(double x)
)
{
fprintf(fp," %0.3f*x %+0.3f\n\n\n", 
 (*PDf)(c), (*P_f)(c) - (*PDf)(c)*c );
}


Crystal Clear mimetype source h.png kg_tan.h
La fonction graphique
/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
void G_Tan_xy(
W_Ctrl w,
double c,
  char fEQ[],
double (*P_f)(double x),
double (*PDf)(double x)
)
{
FILE   *fp;

        fp = fopen("a_main.plt","w");
fprintf(fp,"# Gnuplot file : load \"a_main.plt\" \n\n"
           " set zeroaxis \n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] "
           " %s,\\\n"
           " %0.6f*x %+0.6f,\\\n"
           " \"a_p.plt\" lt 1,\\\n"
           " \"a_a.plt\" lt 1,\\\n"
           " \"a_b.plt\" lt 1\n"
           " reset",
            w.xmini,w.xmaxi,w.ymini,w.ymaxi,
            fEQ,
  ((*PDf)(c)),  (-((*PDf)(c))*c+((*P_f)(c))) );
 fclose(fp);

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

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

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


Un exemple avec la fonction sin.


Résultat dans gnuplot
Tangente04