Mathc gnuplot/Application : Champ de tangentes

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

La tangente dans Wikipedia.

Présentation modifier

N'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.

Dessiner un champ de tangentes 1 modifier

  c01.c
Dessiner la tangente
/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f1.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(-10,10,-400,300),
         i_time(-24.,24.,1),
         feq,
         f,
         Df);

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

 return 0;
}


Résultat dans gnuplot
 


Dessiner un champ de tangentes 2 modifier

  c02.c
Dessiner la tangente
/* ------------------------------------ */
/*  Save as :   c02.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(-2*PI, 2*PI,-4,8),
         i_time(-2.,2.,.1),
         feq,
         f,
         Df);

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

 return 0;
}


Résultat dans gnuplot
 


Dessiner un champ de normales 3 modifier

  c03.c
Dessiner un champ de normales 3
/* ------------------------------------ */
/*  Save as :   c03.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f3.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_NorA(i_WGnuplot(-2,2,-1,2.4),
         i_time(-2,2,.05),
         feq,
         f,
         Df);

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

 return 0;
}


Résultat dans gnuplot
 


Dessiner un champ de normales 4 modifier

  c04.c
Dessiner un champ de normales 4
/* ------------------------------------ */
/*  Save as :   c04.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f1.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_NorA(i_WGnuplot(-2, 2,-1.7,1.7),
         i_time(-2.,2.,.05),
         feq,
         f,
         Df);

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

 return 0;
}


Résultat dans gnuplot
 

Les fichiers h de ce chapitre modifier

  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     "xdef.h"
/* ------------------------------------ */
#include   "kg_tan.h"


  f1.h
La fonction à dessiner
/* ------------------------------------ */
/*  Save as :   f1.h                    */
/* ----------- f ---------------------- */
double f(
double x)
{
 return(       3*x*x-2*x-5);
}
char  feq[] = " 3*x**2-2*x-5";
/* ------------ f' --------------------- */
double Df(
double x)
{
 return(        6*x-2 );
}
char Dfeq[] = " 6*x-2 ";


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


  f3.h
La fonction à dessiner
/* ------------------------------------ */
/*  Save as :   f3.h                    */
/* ----------- f ---------------------- */
double f(
double x)
{
 return(        x*x);
}
char  feq[] = " x**2";
/* ------------ f' --------------------- */
double Df(
double x)
{
 return(        2*x );
}
char Dfeq[] = " 2*x ";


  kg_tan.h
Les fonctions graphiques
/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
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"
           " unset key\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " %s, \\\n",
                 w.xmini,w.xmaxi,w.ymini,w.ymaxi,
                 fEQ);

for(;p<Pic.maxi;p+=Pic.step)
    fprintf(fp," %0.6f*x %+0.6f, \\\n",
           (*PDf)(p), (-(*PDf)(p)*p+(*P_f)(p)) );

     fprintf(fp," %0.6f*x %+0.6f\n",
           (*PDf)(p), (-(*PDf)(p)*p+(*P_f)(p)) );

fprintf(fp," reset");
 fclose(fp);
}
/* ------------------------------------ */
void G_NorA(
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 size ratio -1\n"
           " set zeroaxis\n\n"
           " unset key\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " %s, \\\n",
                 w.xmini,w.xmaxi,w.ymini,w.ymaxi,
                 fEQ);

for(;p<Pic.maxi;p+=Pic.step)
    fprintf(fp," %0.6f*x %+0.6f, \\\n",
           (-1/(*PDf)(p)), (1/(*PDf)(p)*p+(*P_f)(p)) );

     fprintf(fp," %0.6f*x %+0.6f\n",
           (-1/(*PDf)(p)), (1/(*PDf)(p)*p+(*P_f)(p)) );

fprintf(fp," reset");
 fclose(fp);
}