Mathc gnuplot/Animation : Tangente

Un livre de Wikilivres.
Sauter à la navigation Sauter à la recherche
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.

Animer la tangente[modifier | modifier le wikicode]

Nous utilisons ici la méthode avec la commande "pause 1" de gnuplot.

Crystal Clear mimetype source c.png 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[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"


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