Mathc gnuplot/Version imprimable

Un livre de Wikibooks.
Mathc gnuplot
Aller à : Navigation, rechercher


Ceci est la version imprimable de Mathc gnuplot.
  • Ce livre fait environ 100 pages au format A4 (dans la version du 15/06/2007).
  • Si vous imprimez cette page, choisissez « Aperçu avant impression » dans votre navigateur, ou cliquez sur le lien Version imprimable dans la boîte à outils, vous verrez cette page sans ce message, ni éléments de navigation sur la gauche ou en haut.
  • Cliquez sur Rafraîchir cette page pour obtenir la dernière version du wikilivre.
  • Pour plus d'informations sur les version imprimables, y compris la manière d'obtenir une version PDF, vous pouvez lire l'article Versions imprimables.


Mathc gnuplot

Une version à jour et éditable de ce livre est disponible sur Wikilivres,
une bibliothèque de livres pédagogiques, à l'URL:
//fr.wikibooks.org/wiki/Mathc_gnuplot

Vous avez la permission de copier, distribuer et/ou modifier ce document selon les termes de la Licence de documentation libre GNU, version 1.2 ou plus récente publiée par la Free Software Foundation; sans sections inaltérables, sans texte de première page de couverture et sans Texte de dernière page de couverture. Une copie de cette licence est inclue dans l'annexe nommée « Licence de documentation libre GNU ».




L'association de gnuplot au langage c permet de dessiner et d'animer des objets mathématiques en 2D et 3D.









Dessiner


Fichiers h partagés :


Application :


Animer


Application :


Géométrie de la tortue standard


Application :


Géométrie de la tortue vectorielle


Application :


Conclusion


Annexe





Introduction

Préambule

En pratique

Fichiers pour gnuplot

Préambule

f_p=fopen("a.txt","w");//(write)  Créer un fichier en écriture.
f_p=fopen("a.txt","r");//(read)   0uvrir un fichier en lecture.
f_p=fopen("a.txt","a");//(append) 0uvrir un fichier en écriture. 
                       //         Rajouter le texte en fin de fichier.
 
 printf(    "%d",i);   // Imprimer sur l'écran.
fprintf(f_p,"%d",i);   // Imprimer dans le fichier *f_p
sprintf(  s,"%d",i);   // Imprimer dans la chaine de caractères s.

Premiers fichiers

Un fichier list.txt

/* ------------------------------ */
/* Save as c01.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
double f(double x){return(pow(x,2.));}
/* ------------------------------ */
int main(void)
{
FILE   *fp;                   /*Déclarer un pointeur de fichier.   */
double   a;
                              /*Ouvrir le fichier en mode écriture.*/
 fp = fopen("list.txt","w");  /*fp est un pointeur de fichier      */
                              /*qui pointe sur "list.txt"          */
 for(a = -5.0; a  = 5.0; a++)
  fprintf(fp," %6.3f %6.3f\n",/*Imprimer dans le fichier           */
                a,   f(a));
 fclose(fp);                  /*Fermer le fichier                  */
 
 printf("\n\n Ouvrir le fichier list.txt "
        "\n\n Press return to continue.  ");
 getchar();
 return 0;}

Un fichier de données pour Gnuplot

/* ------------------------------ */
/* Save as c02.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
double f(double x){return(pow(x,2.));}
/* ------------------------------ */
int main(void)
{
FILE *fp = fopen("data","w");
double a = -5.0;
 
  for(; a  = 5.0; a+=.2)
     fprintf(fp," %6.3f   %6.3f\n",a,f(a));
  fclose(fp);
 
 printf(" Dans gnuplot -  plot \"data\" \n\n"
        " Press return to continue.     \n\n");
 getchar();
 
 return 0;
}

Un fichier de commande pour Gnuplot

/* ------------------------------ */
/* Save as c03.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
char  heq[] = "sin(x)";
char  geq[] = "cos(x)";
/* ------------------------------ */
int main(void)
{
FILE   *fp = fopen("a_main.plt","w");
 
fprintf(fp,"# Fichier de commande pour Gnuplot          \n"
           "# En ligne de commande : load \"a_main.plt\"\n"
           "#\n\n"
           " set zeroaxis\n"
           " plot %s,\\\n"
           " %s \n\n"
           " reset", geq, heq);
 fclose(fp);
 
 printf("\n\n load \"a_main.plt\" with gnuplot."
        "\n\n Press return to continue.        ");
 getchar();
 
 return 0;
}

Cela donne dans le fichier "a_main.plt" :

# Fichier de commande pour Gnuplot          
# En ligne de commande : load "a_main.plt"
#
 set zeroaxis
 plot cos(x),\
 sin(x) 
 reset

Dessiner un fichier et une chaine de caractères

/* ------------------------------ */
/* Save as c04.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
double f(double x){return(cos(x));}
/* ------------------------------ */
char   feq[] =           "cos(x)";
/* ------------------------------ */
int main(void)
{
FILE *fp;
double a = -5.0;
 
   fp = fopen("data","w");
   for(; a  = 5.0; a+=.2)
        fprintf(fp," %6.3f   %6.3f\n",   a, f(a));
   fclose(fp);
 
   fp = fopen("a_main.plt","w");
   fprintf(fp," set zeroaxis\n"
              " plot \"data\",\\\n"
              " %s\n"
              " reset",feq);
   fclose(fp);
 
 printf("\n\n load \"a_main.plt\" with gnuplot."
        "\n\n Press return to continue.        ");
 getchar();
 
 return 0;
}

Cela donne dans le fichier "a_main.plt" :

set zeroaxis
plot "data",\
cos(x)
reset

Une fonction pour dessiner

//* ------------------------------ */
/* Save as c05.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
double f(double x){return(cos(x));}
char   feq[] = "cos(x)";
/* ------------------------------ */
int G_plot(void)
{
FILE *fp;
double a = -5.0;
 
   fp = fopen("data","w");
   for(; a  = 5.0; a+=.2)
        fprintf(fp," %6.3f   %6.3f\n",a,f(a));
  fclose(fp);
 
  fp = fopen("a_main.plt","w");
   fprintf(fp," set zeroaxis\n"
              " plot \"data\",\\\n"
              " %s\n"
              " reset",feq);
  fclose(fp);
 
return 0;
}
/* ------------------------------ */
int main(void)
{
 G_plot();
 
 printf("\n\n load \"a_main.plt\" with gnuplot."
        "\n\n Press return to continue.        ");
 getchar();
 
 return 0;
}

Cela donne dans le fichier "a_main.plt" :

set zeroaxis
plot "data",\
cos(x)
reset

Les ennuis commencent

/* ------------------------------ */
double g(double x){return(sin(x));}
char   geq[] = "sin(x)";
/* ------------------------------ */

Conclusion

Pointeurs de fonctions


Préambule



double f     (double x){return( pow(x,2.));}
double (*P_f)(double x)


double g     (double x,double y){return(x*y;}
double (*P_g)(double x,double y)



((*P_f)(a))


((*P_g)(a,b))





Exemples graphiques (avec Gnuplot)


Dessiner deux fonctions successivement


/* ------------------------------ */
/* Save as c04.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
double f(double x){return(  pow(x,2.));}
double g(double x){return(2.0*x + 3.0);}
/* ------------------------------ */
void G_plt(
double (*P_f)(double x)
)
{
FILE  *fp = fopen("data","w");
double  a = -5.0;
 
 for(; a  = 5.0; a += 0.3)
   fprintf(fp," %6.3f  %6.3f\n",a,((*P_f)(a)));
 fclose(fp);
}
/* ------------------------------ */
int main(void)
{
 printf(" Type: plot \"data\" ");
    G_plt(f);
 getchar();
 
 printf(" Type: plot \"data\" ");
    G_plt(g);
 
 printf("\n\n Press return to continue.\n");
 getchar();
 
 return 0;
}


Solution pour le chapitre précédent


/* ------------------------------ */
/* Save as c05.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
double f(double x){return(cos(x));}
char   feq[] = "cos(x)";
/* ------------------------------ */
double g(double x){return(sin(x));}
char   geq[] = "sin(x)";
/* ------------------------------ */
int G_plot(
double (*P_f)(double x),
char   Feq[])
{
FILE *fp;
double a = -5.0;
 
 fp = fopen("data","w");
 for(; a  = 5.0; a+=.2)
   fprintf(fp," %6.3f %6.3f\n",a,((*P_f)(a)));
 fclose(fp);
 
 fp = fopen("a_main.plt","w");
 fprintf(fp," set zeroaxis\n"
            " plot \"data\",\\\n"
            " %s\n"
            " reset",Feq);
 fclose(fp);
 
return 0;
}
/* ------------------------------ */
int main(void)
{
 printf(" load \"a_main.plt\" with gnuplot ");
    G_plot(f,feq);
 getchar();
 
 printf(" load \"a_main.plt\" with gnuplot ");
    G_plot(g,geq);
 
 printf("\n\n Press return to continue.\n");
 getchar();
 
 return 0;
}


Résultat après le premier appel de G_plot():

set zeroaxis
plot "data",\
cos(x)
reset


Résultat après le deuxième appel de G_plot():

set zeroaxis
plot "data",\
sin(x)
reset

Exemple numérique


Les fonctions f‘ et f‘‘


/* ------------------------------ */
/* Save as c02.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------ Fonction f ------------ */
double f(double x){return( pow(x,2.));}
/* ------------------------------ */
char  feq[] = "x**2";
/* ------ Fonction g ------------ */
double g(double x){return(
 pow(cos(x),2.)+sin(x)+x-3);}
/* ------------------------------ */
char  geq[] = "cos(x)**2+sin(x)+x-3";
/* ------------------------------
 f'(a) = f(a+h) - f(a-h)
          -------------
              2h
   ------------------------------ */
double Dx_1(
double (*P_f)(double x),/* Declaration de pointeur de fonction */
double a,
double h
)
{
 return( ( ((*P_f)(a+h))-((*P_f)(a-h)) ) / (2.*h) );
}
/* -----------------------------
 f''(a) = f(a+h) - 2 f(a) + f(a-h)
           ----------------------
                     h**2
   ------------------------------- */
double Dx_2(
double (*P_f)(double x),/* Declaration de pointeur de fonction */
double a,
double h
)
{
 return( (((*P_f)(a+h))-2*((*P_f)(a))+((*P_f)(a-h))) / (h*h) );
}
/* ------------------------------ */
int main(void)
{
double x = 2.;
double h = 0.001;
 
printf("\n\n");
 
printf("  f(%.3f) = %.3f  \n",x,f(x)       );
printf(" f'(%.3f) = %.3f  \n",x,Dx_1(f,x,h));
printf("f''(%.3f) = %.3f  \n",x,Dx_2(f,x,h));
 
printf("\n\n");
 
printf("  g(%.3f) = %.3f \n",x,g(x)       );
printf(" g'(%.3f) = %.3f \n",x,Dx_1(g,x,h));
printf("g''(%.3f) = %.3f \n",x,Dx_2(g,x,h));
 
    printf("\n\n Press return to continue.");
 
 getchar();
 
 return 0;
}


Résultat ;

  f(2.000) = 4.000
 f‘(2.000) = 4.000
f‘‘(2.000) = 2.000
.
  g(2.000) = 0.082
 g‘(2.000) = 1.341
g‘‘(2.000) = 0.398
.
Press return to continue.


La fonction FoG


/* ------------------------------ */
/* Save as c03.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------ Fonction f ------------ */
double f(double x){return( pow(x,2.));}
/* ------------------------------ */
char  feq[] = "x**2";
/* ------ Fonction g ------------ */
double g(double x){return(2.0*x + 3.0);}
/* ------------------------------ */
char  geq[] = "2.0*x + 3.0";
/* - Fonction FoG (g suivie de f)-*/
double FoG(
double (*P_F)(double x),/* Pointeur pour la premiere fonction */
double (*P_G)(double x),/* Pointeur pour la deuxieme fonction */
double a
)
{
 return((*P_F)( ((*P_G)(a))) );
}
/* ------------------------------ */
int main(void)
{
double a = 2.0;
 
 printf(" f : x-  %s\n", feq);
 printf(" g : x-  %s\n", geq);
 printf(" \n\n");
 
   printf(" f(g(%.0f)) = %6.1f\n", a, FoG(f,g,a));
   printf(" g(f(%.0f)) = %6.1f\n", a, FoG(g,f,a));
   printf(" f(f(%.0f)) = %6.1f\n", a, FoG(f,f,a));
 
 printf("\n\n Press return to continue.\n");
 getchar();
 
 return 0;
}


Résultat ;

f : x-  x**2
g : x-  2.0*x + 3.0
.
f(g(2)) = 49.0
g(f(2)) = 11.0
f(f(2)) = 16.0
.
Press return to continue.

Tableau de pointeurs de fonctions


Préambule



Tableau de pointeurs de fonctions

Les fonctions trigonométriques


Déclaration du tableau

double (*TrigF[6])(double x) = {cos,sin,tan,atan,asin,acos};



Exemple d'un appel

   cos(.5) == TrigF[0](.5)


Exemple à tester

/* ------------------------------ */
/* Save as c01.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
int main(void)
{
double (*TrigF[6])(double x) = {cos,sin,tan,atan,asin,acos};
 
double x= .5;
int    i=  0;
 
 printf(" Nous avons declare un tableau "
        " de pointeurs de fonctions.\n  "
        " J'ai utilise ici les fonctions predefinie du c.\n");
 
 
  printf("       cos(%.1f)  = %.3f  \n",  x,     cos(x));
  printf(" TrigF[%d](%.1f)) = %.3f\n\n",i,x,TrigF[i](x));
 
 printf(" Press return to continue");
 getchar();
 
 return 0;
}


Application


Résultat dans un fichier

/* ------------------------------ */
/* Save as c02.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
int main(void)
{
FILE   *fp = fopen("list.txt","w");
 
double (*TrigF[6])(double x) = {atan,asin,acos,tan,cos,sin};
 
int    i= 6; 
double x= .1;
 
fprintf(fp,"   x || sin    cos    tan    acos   asin   atan \n");
 
     for(;x =.5;x+=.1)
        {
         fprintf(fp," %.1f ||",x);
         for(i=6;i;)
            fprintf(fp," %.3f ",TrigF[--i](x));
         fprintf(fp,"\n");
        }
 
 fclose(fp);
 
 printf("\n\n Ouvrir le fichier list.txt\n");
 getchar();
 
 return 0;
}


Le résultat :

  x || sin    cos    tan    acos   asin   atan 
0.1 || 0.100  0.995  0.100  1.471  0.100  0.100 
0.2 || 0.199  0.980  0.203  1.369  0.201  0.197 
0.3 || 0.296  0.955  0.309  1.266  0.305  0.291 
0.4 || 0.389  0.921  0.423  1.159  0.412  0.381 
0.5 || 0.479  0.878  0.546  1.047  0.524  0.464 


Remarque : 
* Attention à l'ordre des fonctions dans la déclaration du tableau.
* double (*TrigF[6])(double x) = {atan,asin,acos,tan,cos,sin};


Au démarage :
* La décrémentation ce fait dans le tableau. TrigF[--i](x)
* Il entre 6 dans le tableau.
* 6 est décrémenté -  5 (avant l'appel de la fonction --i)
* La sixième fonctions est appelé (Sin). 
* La numéro cinq. :)


Au final :
* Il entre UN dans le tableau.
* UN est décrémenté -  0
* La première fonctions est appelé (atan).
* La numéro zéro. :))


* i est égal à zéro en rentrant dans la boucle.
* Le cycle est cassé. :(


Résultat à l'écran

/* ------------------------------ */
/* Save as c03.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------------------------------ */
int main(void)
{
double (*TrigF[6])(double x) = {atan,asin,acos,tan,cos,sin};
 
int    i= 6;
double x= .1;
 
     for(;x =.5;x+=.1)
       {
         printf("\n");
         for(i=6;i;) printf(" %.3f ",TrigF[--i](x));
       }
 
 printf("\n\n Press return to continue.\n");
 getchar();
 
 return 0;
}


Les fonctions f‘ et f‘‘


Déclaration du tableau

double (*Derivate[3])(double (*P_f)(double x),double a,double h) = {fx,Dx_1,Dx_2};





Exemple d'un appel

     f(x) == Derivate[0](f,x,0.)



Exemple à tester

/* ------------------------------ */
/* Save as c04.c                  */
/* ------------------------------ */
#include     stdio.h 
#include      math.h 
/* ------ Fonction f ------------ */
double f(double x){return( pow(x,2.));}
/* ------------------------------ */
char  feq[] = "x**2";
/* ------ Fonction g ------------ */
double g(double x){return(
 pow(cos(x),2.)+sin(x)+x-3);}
/* ------------------------------ */
char  geq[] = "cos(x)**2+sin(x)+x-3";
/* ------------------------------ */
double fx(
double (*P_f)(double x),
double a,
double h
)
{
 return( ((*P_f)(a)) );
}
/* ------------------------------
 f'(a) = f(a+h) - f(a-h)
          -------------
              2h
   ------------------------------ */
double Dx_1(
double (*P_f)(double x),
double a,
double h
)
{
 return( ( ((*P_f)(a+h))-((*P_f)(a-h)) ) / (2.*h) );
}
/* -----------------------------
 f''(a) = f(a+h) - 2 f(a) + f(a-h)
           ----------------------
                     h**2
   ------------------------------- */
double Dx_2(
double (*P_f)(double x),
double a,
double h
)
{
 return( (((*P_f)(a+h))-2*((*P_f)(a))+((*P_f)(a-h))) / (h*h) );
}
/* ------------------------------ */
int main(void)
{
double (*Derivate[3])(double (*P_f)(double x),
                      double a,
                      double h) = {fx,Dx_1,Dx_2};
double x = 2;
double h = 0.001;
 
printf("\n\n");
 
printf("  f(%.3f) = %.3f = %.3f \n",x,f(x),       Derivate[0](f,x,0));
printf(" f'(%.3f) = %.3f = %.3f \n",x,Dx_1(f,x,h),Derivate[1](f,x,h));
printf("f''(%.3f) = %.3f = %.3f \n",x,Dx_2(f,x,h),Derivate[2](f,x,h));
 
printf("\n\n");
 
printf("  g(%.3f) = %.3f = %.3f \n",x,g(x),       Derivate[0](g,x,0));
printf(" g'(%.3f) = %.3f = %.3f \n",x,Dx_1(g,x,h),Derivate[1](g,x,h));
printf("g''(%.3f) = %.3f = %.3f \n",x,Dx_2(g,x,h),Derivate[2](g,x,h));
 
 printf("\n\n Press return to continue.");
 getchar();
 
 return 0;
}

Fichiers h partagés

Préambule



En pratique






xdef.h


Préambule

Présentation

Le fichier xdef.h

/* ------------------------------------ */
/*  Save as :   xdef.h                  */
/* ------------------------------------ */
#ifndef PI
#define PI               3.14159265359
#endif
/* ------------------------------------ */
void clrscrn(void)
{
  printf("\n\n\n\n\n\n\n\n\n\n\n"
         "\n\n\n\n\n\n\n\n\n\n\n"
         "\n\n\n\n\n\n\n\n\n\n\n");
}
/* ------------------------------------ */
void Pause(void)
{
int i=300;
int j;
 
  while(--i){j=600000;while(--j);}
}
/* ------------------------------------ */
/* First file name :                    */
/*                                      */
/* char fname[]= "a_paaa";              */
/* ------------------------------------ */
char *NewName(
char *name
)
{
            if(name[5] 'z')
 
               ++name[5];
 
       else if(name[4] 'z')
              {
                 name[5]='a';
               ++name[4];
              }
       else if(name[3] 'z')
              {
                 name[5]='a';
                 name[4]='a';
               ++name[3];
              }
 
 return(name);
}

xplt


Préambule

Présentation

Le fichier xplt.h

/* ------------------------------------ */
/*  Save as :   xplt.h                  */
/* ------------------------------------ */
typedef struct
{
    double  xmini;
    double  xmaxi;
    double  ymini;
    double  ymaxi;
 
}W_Ctrl, *PW_Ctrl;
/* ------------------------------------ */
W_Ctrl i_WGnuplot(
double  xmini,
double  xmaxi,
double  ymini,
double  ymaxi
)
{
W_Ctrl w = {xmini,xmaxi,ymini,ymaxi};
 
return (w);
}
typedef struct
{
    double  xmini;
    double  xmaxi;
    double  ymini;
    double  ymaxi;
    double  zmini;
    double  zmaxi;
 
}Ws_Ctrl, *PWs_Ctrl;
/* ------------------------------------ */
Ws_Ctrl i_WsGnuplot(
double  xmini,
double  xmaxi,
double  ymini,
double  ymaxi,
double  zmini,
double  zmaxi
)
{
Ws_Ctrl w = {xmini,xmaxi,ymini,ymaxi,zmini,zmaxi};
 
return (w);
}
/* ------------------------------------ */
typedef struct
{
    double  rot_x;
    double  rot_z;
    double  scale;
    double  scale_z;
 
}View_Ctrl, *PView_Ctrl;
/* ------------------------------------ */
View_Ctrl i_VGnuplot(
double  rot_x,
double  rot_z,
double  scale,
double  scale_z
)
{
View_Ctrl V = {rot_x,rot_z,scale_z,scale_z};
 
return (V);
}
/* ------------------------------------ */
typedef struct
{
double mini;
double maxi;
double step;
 
}t_Ctrl, *Pt_Ctrl;
/* ------------------------------------ */
t_Ctrl i_time(
double mini,
double maxi,
double step
)
{
t_Ctrl t = {mini,maxi,step};
 
return (t);
}

xspv.h


Préambule

Présentation

Le fichier xspv.h

/* ------------------------------------ */
/*  Save as :   xspv.h                  */
/* ------------------------------------ */
typedef struct
{
    double  x;
    double  y;
 
}point2d, *Ppoint2d;
/* ------------------------------------ */
point2d i_point2d(
double x,
double y
)
{
point2d p = {x,y};
 
return (p);
}
/* ------------------------------------ */
typedef struct
{
    double  x;
    double  y;
    double  z;
 
}point3d, *Ppoint3d;
/* ------------------------------------ */
point3d i_point3d(
double x,
double y,
double z
)
{
point3d p = {x,y,z};
 
return (p);
}
/* ------------------------------------ */
typedef struct
{
    double  i;
    double  j;
 
}vector2d, *Pvector2d;
/* ------------------------------------ */
vector2d i_vector2d(
double i,
double j
)
{
vector2d v = {i,j};
 
return (v);
}
 
/* ------------------------------------ */
typedef struct
{
    double  i;
    double  j;
    double  k;
 
}vector3d, *Pvector3d;
/* ------------------------------------ */
vector3d i_vector3d(
double i,
double j,
double k
)
{
vector3d v = {i,j,k};
 
return (v);
}

xfx_x.h


Préambule

Présentation

Le fichier xfx_x.h

/* ------------------------------------ */
/*  Save as :   xfx_x.h                 */
/* ------------------------------------
 f'(a) = f(a+h) - f(a-h)
          -------------
              2h
   ----------------------------------  */
double fx_x(
double (*P_f)(double x),
double a,
double h
)
{
 return( ( ((*P_f)(a+h))-((*P_f)(a-h)) ) / (2.*h) );
}
/* ------------------------------------
 f''(a) = f(a+h) - 2 f(a) + f(a-h)
           ----------------------
                     h**2
   ----------------------------------  */
double fx_xx(
double (*P_f)(double x),
double a,
double h
)
{
 return( (((*P_f)(a+h))-2*((*P_f)(a))+((*P_f)(a-h))) / (h*h) );
}

xfxy_x.h


Préambule

Présentation

Le fichier xfxy_x.h

/* ------------------------------------ */
/*  Save as :   xfxy_x.h                */
/* ------------------------------------ */
double fxy_x(
double (*P_f)(double x, double y),
double   h,
point2d  p
)
{
double tplsh;
double tmnsh;
 
 tplsh = ((*P_f)(p.x+h,p.y));
 tmnsh = ((*P_f)(p.x-h,p.y));
 
 return(( tplsh-tmnsh)/(2.*h) );
}
/* ------------------------------------ */
double fxy_y(
double (*P_f)(double x, double y),
double   h,
point2d  p
)
{
double tplsh;
double tmnsh;
 
 tplsh = ((*P_f)(p.x,p.y+h));
 tmnsh = ((*P_f)(p.x,p.y-h));
 
 return(( tplsh-tmnsh)/(2.*h) );
}
/* ------------------------------------ */
double fxy_xx(
double (*P_f)(double x, double y),
double   h,
point2d  p
)
{
double t;
double tplsh;
double tmnsh;
 
 t     = ((*P_f)(p.x  , p.y));
 tplsh = ((*P_f)(p.x+h, p.y));
 tmnsh = ((*P_f)(p.x-h, p.y));
 
 return( (tplsh-2*t+tmnsh)/(h*h) );
}
/* ------------------------------------ */
double fxy_yy(
double (*P_f)(double x, double y),
double   h,
point2d  p
)
{
double t;
double tplsh;
double tmnsh;
 
 t     = ((*P_f)(p.x, p.y  ));
 tplsh = ((*P_f)(p.x, p.y+h));
 tmnsh = ((*P_f)(p.x, p.y-h));
 
 return( (tplsh-2*t+tmnsh)/(h*h) );
}

xfxyz_x.h


Préambule

Présentation

Le fichier xfxyz_x.h

/* ------------------------------------ */
/*  Save as :   xfxyz_x.h               */
/* ------------------------------------ */
double fxyz_x(
double (*P_f)(double x, double y, double z),
double   h,
point3d  p
)
{
double tplsh;
double tmnsh;
 
 tplsh = ((*P_f)(p.x+h,p.y,p.z));
 tmnsh = ((*P_f)(p.x-h,p.y,p.z));
 
 return(( tplsh-tmnsh)/(2.*h) );
}
/* ------------------------------------ */
double fxyz_y(
double (*P_f)(double x, double y, double z),
double   h,
point3d  p
)
{
double tplsh;
double tmnsh;
 
 tplsh = ((*P_f)(p.x,p.y+h,p.z));
 tmnsh = ((*P_f)(p.x,p.y-h,p.z));
 
 return(( tplsh-tmnsh)/(2.*h) );
}
/* ------------------------------------ */
double fxyz_z(
double (*P_f)(double x, double y, double z),
double   h,
point3d  p
)
{
double tplsh;
double tmnsh;
 
 tplsh = ((*P_f)(p.x,p.y,p.z+h));
 tmnsh = ((*P_f)(p.x,p.y,p.z-h));
 
 return(( tplsh-tmnsh)/(2.*h) );
}

Application : Fonction Heaviside


Préambule


La fonction Heaviside

\forall x \in \R,\ H(x)=\left\{\begin{matrix} 1 & \mathrm{si} & x   0 \\  & \mathrm{sinon} & 0 \end{matrix}\right.


Présentation


/* ------------------------------------ */
double H(
double x)
{
       if(x 0.)return(1.);
       else    return(0.);
}
/* ------------------------------------ */



/* ------------------------------------ */
/*  Save as :  c01.c                    */
/* ------------------------------------ */
#include "x_ahfile.h"
/* ------------------------------------ */
int main(void)
{
 printf(" H : if(x 0) 1 else 0 \n");
 
      G_plot(i_WGnuplot(-2.,20.,-1.,2.),
             i_time(-2.,20.,0.001),
             H);
 
 printf("\n  load \"a_main.plt\" with gnuplot."
        "\n  Press return to continue         ");
 getchar();
 
 return 0;
}


Une application


/* ------------------------------------ */
/*  Save as :  c02.c                    */
/* ------------------------------------ */
#include "x_ahfile.h"
/* ------------------------------------ */
double v(
double x)
{
double n=0, r=0;
 
 for(;n 20;++n) r += pow(-1,n)*H(x-n);
 
 return(r);
}
char veq[] = "Sum((-1)^n*H(x-n),n=0..20)";
/* ------------------------------------ */
int main(void)
{
 printf(" H : if(x 0) 1 else 0 \n\n"
        " v : x-  %s           \n\n",veq);
 
      G_plot(i_WGnuplot(-2.,20.,-1.,2.),
             i_time(-2.,20.,0.001),
             v);
 
 printf("\n\n 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

Appel des fichiers standards

/*  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   "fh.h"
#include  "g_f.h"


La fonction Heaviside

/* ------------------------------------ */
/*  Save as :  fh.h                     */
/* ------------------------------------ */
double H(
double x)
{
       if(x 0.)return(1.);
       else    return(0.);
}
/* ------------------------------------ */


La fonction graphique

/* ------------------------------------ */
/*  Save as :   g_f.h                   */
/* ------------------------------------ */
void G_plot(
W_Ctrl W,
t_Ctrl T,
double (*P_f1)(double x)
)
{
FILE  *fp;
double  t;
 
        fp = fopen("a_main.plt","w");
fprintf(fp," set zeroaxis lt 8\n"
           " set grid\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " \"data\" with line lt 3\n"
           " reset",
             W.xmini,W.xmaxi,W.ymini,W.ymaxi);
 fclose(fp);
 
        fp = fopen("data","w");
 for(t=T.mini; t =T.maxi; t+=T.step)
     fprintf(fp," %6.3f   %6.3f\n",t,(*P_f1)(t));
 fclose(fp);
}


set zeroaxis lt 8
set grid
plot [-2.000:20.000] [-1.000:6.000] \
"data" with line lt 3 
reset


Conclusion


Application : Tangente


Préambule


Présentation


Dessiner la tangente

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
double c = 2;
 
 printf("  f : x-  %s\n\n",   feq);
 printf("  f': x-  %s\n\n\n",Dfeq);
 
 printf(" With c = %0.3f, the equation of the tangent is :",c);
 printf("\n\n    y = f'(c) (x-c) + f(c) =");
 eq_Tan(c,f,Df);
 
 G_Tan(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)
 f': x-   (-sin(x)) 
.
With c = 2.000, the equation of the tangent is :
.
   y = f'(c) (x-c) + f(c) = -0.909*x +1.402
.
load "a_main.plt" with gnuplot.


Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


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


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


La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
void G_Tan(
W_Ctrl w,
double c,
  char    fEQ[],
double (*P_f)(double x),
double (*PDf)(double x)
)
{
FILE *fp = fopen("a_main.plt","w");
 
fprintf(fp," set zeroaxis\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " %s, \\\n"
           " %0.6f*x %+0.6f lw 3\n"
           " reset",
            w.xmini,w.xmaxi,w.ymini,w.ymaxi,
            fEQ,
            (*PDf)(c),
            (-(*PDf)(c)* c + (*P_f)(c)));
 
 fclose(fp);
}


Exemple avec sortie fichier

/* ------------------------------------ */
/*  Save as :   c01f.c                  */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
FILE *fp = fopen("a_out.txt","w");
double c = 0;
 
fprintf(fp,"  f : x-  %s\n\n",   feq);
fprintf(fp,"  f': x-  %s\n\n\n",Dfeq);
 
fprintf(fp," With c = %0.3f, the equation of the tangent is :",c);
fprintf(fp,"\n\n    y = f'(c) (x-c) + f(c) =");
eq_Tanf(fp,c,f,Df);
 
G_Tan(i_WGnuplot(-7, 7,-2,2),c,feq,f,Df);
 
fprintf(fp," load \"a_main.plt\" with gnuplot.");
 fclose(fp);
 
 printf(" Read \"a_out.txt\".\n"
        " Press return to continue");
 
  getchar();
 
 return 0;
}


Le résultat

 f : x-   cos(x)
 f': x-   (-sin(x)) 
 .
With c = 0.000, the equation of the tangent is :
.
   y = f'(c) (x-c) + f(c) = -0.000*x +1.000
.
load "a_main.plt" with gnuplot.


Résultat dans gnuplot

Conclusion

Application : Tangente et axes x-y


Préambule

Présentation

Dessiner

/* ------------------------------------ */
/*  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


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


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


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


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 = fopen("a_main.plt","w");
FILE   *fq = fopen(   "a_p.plt","w");
FILE   *fr = fopen(   "a_a.plt","w");
FILE   *fs = fopen(   "a_b.plt","w");
 
fprintf(fp," 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);
 
fprintf(fq," %0.6f   %0.6f",
             c, ((*P_f)(c)));
 fclose(fq);
 
fprintf(fr," %0.6f   0.",
c-((*P_f)(c))/((*PDf)(c)));
 fclose(fr);
 
fprintf(fs," 0.   %0.6f",
((*P_f)(c))-(((*PDf)(c))*c));
 fclose(fs);
}


Exemple avec sortie fichier

/* ------------------------------------ */
/*  Save as :   c01f.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
FILE *fp = fopen("a_out.txt","w");
double c = 1;
 
fprintf(fp,"  f : x-  %s  \n", feq);
fprintf(fp," Df : x-  %s\n\n",Dfeq);
 
fprintf(fp," With c = %0.3f, the equation of"
           " the tangent is :\n\n"
           "      y =  Df(c) (x-c) + f(c) = ",c);
eq_Tanf(fp,c,f,Df);
 
fprintf(fp," Find at c = %0.3f\n\n"
           " the intersection points of the"
           " tangent with the x-y axis.\n\n",c);
 
fprintf(fp," P(%5.3f, %5.3f)     P(c, f(c))\n",
        c, f(c));
 
fprintf(fp," A(%5.3f, 0.000)     A(c-f(c)/Df(c), 0)\n",
        c-(f(c))/(Df(c)));
 
fprintf(fp," 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);
 
fprintf(fp," load \"a_main.plt\" with gnuplot.");
 fclose(fp);
 
 printf(" Read \"a_out.txt\".\n"
        " Press return to continue");
 getchar();
 
 return 0;
}
Résultat dans gnuplot


Conclusion

Application : Tangente de P à l'axes des x


Préambule


Présentation


Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
double c = .5;
 
 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 PA, the length of the tangent from P to the x axis.\n\n");
 
 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\n\n",
          c-(f(c)/Df(c)));
 
 printf(" PA =  sqrt(f(c)**2*(1 +(1/Df(c)**2))) = %6.3f\n\n\n",
        sqrt(pow(f(c),2)*(1+(1/pow(Df(c),2)))));
 
 G_TanPx      (i_WGnuplot(-2,4,-1,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 = 0.500, the equation of the tangent is :
.
     y =  Df(c) (x-c) + f(c) =  -0.479*x +1.117
.
Find PA, the length of the tangent from P to the x axis.
.
P(0.500, 0.878)           P(c, f(c))       
A(2.330, 0.000)           A(c-f(c)/Df(c), 0)
.
PA =  sqrt(f(c)**2*(1 +(1/Df(c)**2))) =  2.030
.
load "a_main.plt" with gnuplot.
Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


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


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


La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
void G_TanPx(
W_Ctrl w,
double c,
  char    fEQ[],
double (*P_f)(double x),
double (*PDf)(double x)
)
{
FILE   *fp = fopen("a_main.plt","w");
FILE   *ft = fopen("a_xaxe.plt","w");
 
fprintf(fp," set zeroaxis \n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " %s,\\\n"
           " %0.6f*x %+0.6f,\\\n"
           " \"a_xaxe.plt\" with linesp lt 3 \n"
           " reset",
             w.xmini,w.xmaxi,w.ymini,w.ymaxi,
            fEQ,
       (*PDf)(c),-(*PDf)(c)*c+(*P_f)(c) );
 fclose(fp);
 
fprintf(ft," %0.6f   %0.6f\n",c,(*P_f)(c) );
fprintf(ft," %0.6f   0.   \n",
c-((*P_f)(c)/(*PDf)(c)));
 fclose(ft);
}


Exemple avec sortie fichier

/* ------------------------------------ */
/*  Save as :   c01f.c                  */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
FILE *fp = fopen("a_out.txt","w");
double c = .5;
 
fprintf(fp,"  f : x-  %s  \n", feq);
fprintf(fp,"  Df: x-  %s\n\n",Dfeq);
 
fprintf(fp," With c = %0.3f, the equation of the tangent is :\n\n"
        "      y =  Df(c) (x-c) + f(c) = ",c);
 eq_Tanf(fp,c,f,Df);
 
fprintf(fp," Find PA, the length of the tangent from P to the x axis.\n\n");
 
fprintf(fp," P(%5.3f, %5.3f)           P(c, f(c))       \n",
        c,f(c));
 
fprintf(fp," A(%5.3f, 0.000)           A(c-f(c)/Df(c), 0)\n\n\n",
          c-(f(c)/Df(c)));
 
fprintf(fp," PA =  sqrt(f(c)**2*(1 +(1/Df(c)**2))) = %6.3f\n\n\n",
        sqrt(pow(f(c),2)*(1+(1/pow(Df(c),2)))));
 
 G_TanPx      (i_WGnuplot(-2,4,-1,2),
                 c,
               feq,f,Df);
 
fprintf(fp," load \"a_main.plt\" with gnuplot.");
 fclose(fp);
 
 printf(" Read \"a_out.txt\".\n"
        " Press return to continue");
 
  getchar();
 
 return 0;
}
Résultat dans gnuplot

Conclusion

Application : Tangente de P à l'axes des y


Préambule

Présentation


Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
double c = .5;
 
 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 PB, the length of the tangent from P to the y axis.\n\n");
 
 printf(" P(%5.3f,  %5.3f)    P(c, f(c))          \n", 
        c, f(c));
 
 printf(" B(0.000,  %5.3f)    B(0, f(c)-c*Df(c))\n\n", 
        f(c)-c*Df(c));
 
 printf(" PB = sqrt(c**2*(1+Df(c)**2)) = %6.3f \n\n", 
 sqrt(c*c*(1+pow(Df(c),2))));
 
 G_TanPy      (i_WGnuplot(-2,4,-1,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 = 0.500, the equation of the tangent is :
.
     y =  Df(c) (x-c) + f(c) =  -0.479*x +1.117
.
Find PB, the length of the tangent from P to the y axis.
.
P(0.500,  0.878)    P(c, f(c))          
B(0.000,  1.117)    B(0, f(c)-c*Df(c))
.
PB = sqrt(c**2*(1+Df(c)**2)) =  0.554 
.
load "a_main.plt" with gnuplot.
Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


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


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


La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
void G_TanPy(
W_Ctrl w,
double c,
  char fEQ[],
double (*P_f)(double x),
double (*PDf)(double x)
)
{
FILE   *fp = fopen("a_main.plt","w");
FILE   *ft = fopen("a_yaxe.plt","w");
 
fprintf(fp," set zeroaxis\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " %s, \\\n"
           " %0.6f*x %+0.6f, \\\n"
           " \"a_yaxe.plt\" with linesp lt 3\n"
           " reset",
             w.xmini,w.xmaxi,w.ymini,w.ymaxi,
             fEQ, 
    ((*PDf)(c)) ,(-((*PDf)(c))* c + ((*P_f)(c))));
 fclose(fp);
 
fprintf(ft," %0.5f   %0.5f\n",c,((*P_f)(c)));
fprintf(ft," 0.000   %0.5f", 
((*P_f)(c))-(((*PDf)(c))*c));
 fclose(ft);
}


Exemple avec sortie fichier

/* ------------------------------------ */
/*  Save as :   c01f.c                  */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
FILE *fp = fopen("a_out.txt","w");
double c = .5;
 
fprintf(fp,"  f : x-  %s  \n", feq);
fprintf(fp,"  Df: x-  %s\n\n",Dfeq);
 
fprintf(fp," With c = %0.3f, the equation of the tangent is :\n\n"
        "      y =  Df(c) (x-c) + f(c) = ",c);
 eq_Tanf(fp,c,f,Df);
 
fprintf(fp," Find PB, the length of the tangent from P to the y axis.\n\n");
 
fprintf(fp," P(%5.3f,  %5.3f)    P(c, f(c))          \n",
        c, f(c));
 
fprintf(fp," B(0.000,  %5.3f)    B(0, f(c)-c*Df(c))\n\n",
        f(c)-c*Df(c));
 
fprintf(fp," PB = sqrt(c**2*(1+Df(c)**2)) = %6.3f \n\n",
 sqrt(c*c*(1+pow(Df(c),2))));
 
 G_TanPy      (i_WGnuplot(-2,4,-1,2),
                 c,
               feq,f,Df);
 
fprintf(fp," load \"a_main.plt\" with gnuplot.");
 fclose(fp);
 
 printf(" Read \"a_out.txt\".\n"
        " Press return to continue");
 
  getchar();
 
 return 0;
}
Résultat dans gnuplot

Conclusion

Application : Sous tangente


Préambule


Présentation


Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
double c = .5;
 
 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 AM, the length of the under tangent.\n\n");
 
 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(" M(%5.3f, 0.000)         M( c, 0)\n\n\n", c);
 
 printf(" AM = sqrt((f(c)**2)/(Df(c)**2)) = %6.3f\n\n\n", 
         sqrt(f(c)*f(c)*(1/(Df(c)*Df(c)))));
 
  G_TanxM    (i_WGnuplot(-2,4,-1,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-   sin(x)  
 Df: x-   (cos(x)) 
.
With c = 0.500, the equation of the tangent is :
.
     y =  Df(c) (x-c) + f(c) =  0.878*x +0.041
.
Find AM, the length of the under tangent.
.
P(0.500, 0.479)         P(c, f(c))    
A(-0.046, 0.000)         A(c-f(c)/Df(c), 0)
M(0.500, 0.000)         M( c, 0)
.
AM = sqrt((f(c)**2)/(Df(c)**2)) =  0.546
.
load "a_main.plt" with gnuplot.
Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


Déclaration et initialisation des structures

/* ------------------------------------ */
/*  Save as :   xa_strct.h              */
/* ------------------------------------ */
typedef struct
{
    double  xmini;
    double  xmaxi;
    double  ymini;
    double  ymaxi;
 
}W_Ctrl, *PW_Ctrl;
/* ------------------------------------ */
W_Ctrl i_WGnuplot(
double  xmini,
double  xmaxi,
double  ymini,
double  ymaxi
)
{
W_Ctrl w = {xmini,xmaxi,ymini,ymaxi};
 
return (w);
}


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


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


La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
void G_TanxM(
W_Ctrl w,
double c,
  char   fEQ[],
double (*P_f)(double x),
double (*PDf)(double x)
)
{
FILE   *fp = fopen("a_main.plt","w");
FILE   *ft = fopen("a_px.plt",  "w");
FILE   *fr = fopen("a_am.plt",  "w");
 
fprintf(fp," set zeroaxis \n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
           " %s,\\\n"
           " %0.6f*x %+0.6f,\\\n"
           " \"a_px.plt\" with linesp lt 3,\\\n"
           " \"a_am.plt\" with linesp lt 4 \n"
           " reset",
             w.xmini,w.xmaxi,w.ymini,w.ymaxi,fEQ,
        ((*PDf)(c)),(-(*PDf)(c)*c+(*P_f)(c)));
 fclose(fp);
 
fprintf(ft," %0.6f   %0.6f\n", c,((*P_f)(c)));
fprintf(ft," %0.6f   0.",
 c-(((*P_f)(c))/((*PDf)(c))) );
 fclose(ft);
 
fprintf(fr," %0.6f   0.\n",
c-(((*P_f)(c))/((*PDf)(c))));
fprintf(fr," %0.6f   0.", c);
 fclose(fr);
}


Exemple avec sortie fichier

/* ------------------------------------ */
/*  Save as :   c01f.c                  */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
FILE *fp = fopen("a_out.txt","w");
double c = .5;
 
fprintf(fp,"  f : x-  %s  \n", feq);
fprintf(fp,"  Df: x-  %s\n\n",Dfeq);
 
fprintf(fp," With c = %0.3f, the equation of the tangent is :\n\n"
        "      y =  Df(c) (x-c) + f(c) = ",c);
 eq_Tanf(fp,c,f,Df);
 
fprintf(fp," Find AM, the length of the under tangent.\n\n");
 
fprintf(fp," P(%5.3f, %5.3f)         P(c, f(c))    \n",
        c, f(c));
 
fprintf(fp," A(%5.3f, 0.000)         A(c-f(c)/Df(c), 0)\n",
        c-(f(c)/Df(c)));
fprintf(fp," M(%5.3f, 0.000)         M( c, 0)\n\n\n", c);
 
fprintf(fp," AM = sqrt((f(c)**2)/(Df(c)**2)) = %6.3f\n\n\n",
         sqrt(f(c)*f(c)*(1/(Df(c)*Df(c)))));
 
  G_TanxM    (i_WGnuplot(-2,4,-1,2),
                 c,
               feq,f,Df);
 
fprintf(fp," load \"a_main.plt\" with gnuplot.");
 fclose(fp);
 
 printf(" Read \"a_out.txt\".\n"
        " Press return to continue");
 
  getchar();
 
 return 0;
}
Résultat dans gnuplot

Conclusion

Application : Cercle de courbure


Préambule

Présentation

Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fb.h"
/* ------------------------------------ */
int main(void)
{
double x = 0.;
double e = .001;
 
   circle("a_circle.plt",
          1./K_y_2d(f,x,e),
          h_y_2d(f,x,e),
          k_y_2d(f,x,e));
 
   G_C_2d(i_WGnuplot(-4.,4.,-2.,2.),
          f,x,e,
          feq);
 
 clrscrn();
 
 printf(" If a smooth curve C is the graph of y = f(x),\n"
        " then the curvature K at P(x,y) is\n\n\n"
        " K = |y''| / [1 + y'^2]^(3/2)     \n\n\n"
 
        " If P(x,y) is a point on the graph "
        "of y = f(x)  \n"
        " at which K != 0. The point M(h,k)"
        " is the center\n"
        " of the cuvature for P if   \n\n\n"
        " h = x - y'[1 + y'^2] / y''     \n"
        " k = y +   [1 + y'^2] / y'' \n\n\n"
 
        " The radius is r = 1/K \n\n\n"
 
        " Open the file \"a_main.plt\" with Gnuplot.\n\n");
 
 printf("\n Press return to continue");
 getchar();
 
 return 0;
}

Le résultat.

Résultat dans gnuplot
Résultat dans gnuplot
Résultat dans gnuplot

Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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    "xfx_x.h"
/* ------------------------------------ */
#include  "kradius.h"
#include     "kg_c.h"
#include  "kcircle.h"


Calcul du cercle

/* ------------------------------------ */
/*  Save as :   kradius.h               */
/* ------------------------------------ */
double K_y_2d(
double (*P_f)(double x),
double x,
double e
)
{
double a = fx_x((*P_f),x,e);
 
 return(fabs(fx_xx((*P_f),x,e))
                   /
             pow(1+a*a,3./2.));
}
/* ------------------------------------ */
double h_y_2d(
double (*P_f)(double x),
double x,
double e
)
{
double a = fx_x((*P_f),x,e);
 
 return(x - ( ( a*(1+a*a) )
              /
        fx_xx((*P_f),x,e)));
}
/* ------------------------------------ */
double k_y_2d(
double (*P_f)(double x),
double x,
double e
)
{
double a = fx_x((*P_f),x,e);
 
 return((*P_f)(x) + (    (1+a*a)
                  /
           fx_xx((*P_f),x,e)));
}

La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   fb.h                    */
/* ------------------------------------ */
double f(
double x)
{
        return( cos(x));
}
char  feq[] =  "cos(x)";

La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_c.h                  */
/* ------------------------------------ */
void G_C_2d(
W_Ctrl W,
double (*P_f)(double x),
double x,
double e,
char   feq[]
)
{
FILE   *fp;
 
        fp = fopen("a_main.plt","w");
fprintf(fp," reset\n"
           " set zeroaxis lt 8\n"
           " set size ratio -1\n"
           " set grid\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
           " \"a_radius.plt\" with linespoints,\\\n"
           " \"a_circle.plt\" with line,\\\n"
           " %s with line\n",
    W.xmini,W.xmaxi,W.ymini,W.ymaxi,feq);
 fclose(fp);
 
        fp = fopen("a_radius.plt","w");
fprintf(fp," %6.5f   %6.5f\n",h_y_2d((*P_f),x,e),
                              k_y_2d((*P_f),x,e));
fprintf(fp," %6.5f   %6.5f\n",x,(*P_f)(x));
             fclose(fp);
 
 Pause();
}

Le cercle

/* ------------------------------------ */
/*  Save as :   kcircle.h               */
/* ------------------------------------ */
void circle(
char   Name[FILENAME_MAX],
double r,
double x,
double y
)
{
FILE   *fp = fopen(Name,"w");
double   t = 0.;
 
for(;t 2.01*PI;t+=.1)
fprintf(fp," %6.5f %6.5f\n",r*cos(t)+x,r*sin(t)+y);
 fclose(fp);
}

Application : Méthode de Newton


Préambule

Présentation

Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
int         n = 5;
double FirstA = 0.5;
 
 clrscrn();
 printf(" Use Newton's method to approximate"
        " the intersection point of :\n\n");
 printf(" g : x-  %s\n\n", geq);
 printf(" and\n\n");
 printf(" h : x-  %s\n\n", heq);
 
 G_gh(i_WGnuplot(-4,4,-4,4), geq,heq);
 
 printf(" To see the graphs of g and h, open the"
        " file \"a_main.plt\" with Gnuplot.\n\n"
        " You can see that, the intersection"
        " point is between 0.0 and 1.0.\n\n"
        " Choose x = %.1f as a first approximation.\n\n",FirstA);
 getchar();
 
 clrscrn();
 printf(" In fact we want find sin(x) = cos(x)"
        " or sin(x) - cos(x) = 0.\n\n"
        " We want find a root of\n\n"
        " f : x-  %s\n\n", feq);
 getchar();
 
 clrscrn();
 printf(" As a first approximation x = %.1f \n\n"
        " The Newton's method give :        \n\n",FirstA);
 
     G_gh_x_0(i_WGnuplot(-4,4,-4,4),
               geq,
               heq,
                 g,
               Newton_s_Method(FirstA,n,f,Df));
 
 printf("\n\n load \"a_main.plt\" with gnuplot. "
        "\n\n Press return to continue");
 getchar();
 
 return 0;
}

Le résultat.

Use Newton's method to approximate the intersection point of :
g : x-  sin(x)
and
h : x-  cos(x)
.
To see the graphs of g and h, open the file "a_main.plt" with Gnuplot.
.
You can see that, the intersection point is between 0.0 and 1.0.
Choose x = 0.5 as a first approximation.
In fact we want find sin(x) = cos(x) or sin(x) - cos(x) = 0.
We want find a root of
.
f : x-  sin(x) - cos(x)
.
As a first approximation x = 0.5 
.
The Newton's method give :        
.
x[1] = 0.500000000000000
x[2] = 0.793407993026023
x[3] = 0.785397992096516
x[4] = 0.785398163397448
x[5] = 0.785398163397448
.
load "a_main.plt" with gnuplot.


Résultat dans gnuplot
As a first approximation x = -2.5 
.
The Newton's method give :        
.
x[1] = -2.500000000000000
x[2] = -2.355194920430497
x[3] = -2.356194490525248
x[4] = -2.356194490192345
x[5] = -2.356194490192345


Résultat dans gnuplot

Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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  "knewton.h"
#include    "kg_gh.h"


La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   f2.h                    */
/* ------------------------------------ */
double g(
double x)
{
        return(sin(x));
}
char  geq [] = "sin(x)";
/* ------------------------------------ */
double Dg(
double x)
{
          return(cos(x));
}
char  Dgeq [] = "cos(x)";
/* ------------------------------------ */
/* ------------------------------------ */
double h(
double x)
{
        return(cos(x));
}
char  heq [] = "cos(x)";
/* ------------------------------------ */
double Dh(
double x)
{
          return(- sin(x));
}
char  Dheq [] = "- sin(x)";
/* ------------------------------------ */
/* ------------------------------------ */
double f(
double x)
{
         return(sin(x) - cos(x));
}
char  feq [] = "sin(x) - cos(x)";
/* ------------------------------------ */
double Df(
double x)
{
          return(cos(x) + sin(x));
}
char  Dfeq [] = "cos(x) + sin(x)";

Méthode de Newton

/* ------------------------------------ */
/*  Save as :   knewton.h               */
/* ------------------------------------
   x_n+1 = x_n -  f(x_n)
                 ------
                 f'(x_n)
  ------------------------------------ */
double Newton_s_Method(
double x,
   int imax,
double (*P_f)(double x),
double (*PDf)(double x)
)
{
int i=1;
 
   for(;i =imax;i++)
      {
       printf(" x[%d] = %.15f\n",i,x);
       x -= ((*P_f)(x))/((*PDf)(x));
      }
return(x);
}


Fonctions graphiques

/* ------------------------------------ */
/*  Save as :   kg_gh.h                */
/* ------------------------------------ */
void G_gh(
W_Ctrl w,
  char geq[],
  char heq[]
)
{
FILE   *fp = fopen("a_main.plt","w");
 
fprintf(fp," set zeroaxis lt 8\n"
           " set grid\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " %s, \\\n"
           " %s  \n"
           " reset",
           w.xmini,w.xmaxi,w.ymini,w.ymaxi,
           geq,heq);
 
 fclose(fp);
}
/* ------------------------------------ */
void G_gh_x_0(
W_Ctrl  w,
  char  geq[],
  char  heq[],
double (*P_g)(double x),
double  x_0
)
{
FILE   *fp = fopen("a_main.plt","w");
FILE   *fq = fopen( "a_x_0.plt","w");
 
fprintf(fp," set zeroaxis lt 8\n"
           " set grid\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " %s, \\\n"
           " %s, \\\n"
           " \"a_x_0.plt\" pt 7 ps 3 \n"
           " reset",
           w.xmini,w.xmaxi,w.ymini,w.ymaxi,
           geq,heq);
 fclose(fp);
 
fprintf(fq," %0.6f   %0.6f", x_0,(*P_g)(x_0));
 fclose(fq);
}


Conclusion

Application : Tangente d'une courbe


Préambule

Présentation


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

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


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

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

Conclusion

Application : Tangente et axes x-y


Préambule

Présentation

Dessiner

/* ------------------------------------ */
/*  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

Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


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

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

Le résultat :

set zeroaxis
plot [-10.000:10.000] [-5.000:5.000]\
"data.plt" with line lt 1,\
-0.867865*x -2.028567, \
"p.plt" lt 1, \
"px.plt" lt 1,\
"py.plt" lt 1   
reset

Conclusion

Application : Tangente de P à l'axes des x


Préambule

Présentation

Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fe.h"
/* ------------------------------------ */
int main(void)
{
double c = PI/4;
 
 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(" With c = %0.3f, the equation of the tangent is :\n\n"
        " y =  ((Dg/Dy)(c))(x-f(c))+g(c) = ",c);
 eq_Tan(f,g,DgDf,c);
 
 printf("\n\n\n");
 
 printf(" Find PA, the length of the tangent from P to the x axis.\n\n");
 
 printf(" P(%6.3f, %6.3f)    P(f(c), g(c))                 \n",
        f(c),g(c));
 
 printf(" A(%6.3f,  0.000)    A(f(c)-g(c)/(DgDf)(c), 0)\n\n\n",
          f(c)-g(c)/(DgDf)(c));
 
 printf(" PA =  sqrt(g(c)**2*(1+(DgDf(c)**2))/(DgDf(c)**2))\n"
        "    = %6.3f\n\n",
       sqrt(pow(g(c),2)*(1/pow(DgDf(c),2)+1)) );
 
     G_TanLx(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)
.
With c = 0.785, the equation of the tangent is :
y =  ((Dg/Dy)(c))(x-f(c))+g(c) =  0.500*x +1.414
.
Find PA, the length of the tangent from P to the x axis.
P( 1.414,  2.121)    P(f(c), g(c))                 
A(-2.828,  0.000)    A(f(c)-g(c)/(DgDf)(c), 0)
.
PA =  sqrt(g(c)**2*(1+(DgDf(c)**2))/(DgDf(c)**2))
   =  4.743
.
To see the curve C, open the file "a_main.plt" with Gnuplot.
Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


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

La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
void eq_Tan(
double (*P_f)  (double t),
double (*P_g)  (double t),
double (*PDgDf)(double t),
double c
)
{
  printf(" %0.3f*x %+0.3f",
(*PDgDf)(c),(-(*PDgDf)(c)*(*P_f)(c)+(*P_g)(c)));
}
/* ------------------------------------ */
void G_TanLx(
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"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
           " \"a_pts.plt\" with line lt 1,   \\\n"
           " %0.6f*x %+0.6f,                 \\\n"
           " \"axp.plt\" with linesp lt 3      \n"
           " reset",
        W.xmini,W.xmaxi,W.ymini,W.ymaxi,
(*PDgDf)(c),(-(*PDgDf)(c)*(*P_f)(c)+(*P_g)(c)));
 fclose(fp);
 
        fp = fopen("a_pts.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("axp.plt","w");
     fprintf(fp," %0.6f %0.6f\n",(*P_f)(c),(*P_g)(c));
     fprintf(fp," %0.6f  0.  \n",
                 (*P_f)(c)-(*P_g)(c)/(*PDgDf)(c));
     fclose(fp);
}

Le résultat :

set zeroaxis
plot [-10.000:10.000] [-5.000:5.000]\
"a_pts.plt" with line lt 1, \
0.500000*x +1.414214,       \
"axp.plt" with linesp lt 3      
reset

Conclusion

Application : Tangente de P à l'axes des y


Préambule

Présentation

Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fe.h"
/* ------------------------------------ */
int main(void)
{
double c = PI/4.;
 
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(" With c = %0.3f, the equation of the tangent is :\n\n"
        " y =  ((Dg/Dy)(c))(x-f(c))+g(c) = ",c);
 eq_Tan(f,g,DgDf,c);
 
 printf("\n\n\n");
 
 printf(" Find PB, the length of the tangent from P to the y axis.\n\n");
 
 printf(" P(%6.3f, %6.3f)    P(f(c), g(c))                 \n",
        f(c),g(c));
 
 printf(" B(+0.000, %6.3f)    B(0, g(c)-f(c)*DgDf(c))\n\n\n",
           g(c)-DgDf(c)*f(c));
 
 printf(" PB =  sqrt(f(c)**2*(1+DgDf(c)**2))\n"
        "    = %6.3f\n\n",
       sqrt(pow(f(c),2)*(1+pow(DgDf(c),2))));
 
     G_TanLy(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)
.
With c = 0.785, the equation of the tangent 
y =  ((Dg/Dy)(c))(x-f(c))+g(c) =  0.500*x +1.414
.
Find PB, the length of the tangent from P to the y axis.
.
P( 1.414,  2.121)    P(f(c), g(c))                 
B(+0.000,  1.414)    B(0, g(c)-f(c)*DgDf(c))
.
PB =  sqrt(f(c)**2*(1+DgDf(c)**2))
   =  1.581
.
To see the curve C, open the file "a_main.plt" with Gnuplot.
Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


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

La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_tan.h                */
/* ------------------------------------ */
void eq_Tan(
double (*P_f)  (double t),
double (*P_g)  (double t),
double (*PDgDf)(double t),
double c
)
{
 printf(" %0.3f*x %+0.3f",
(*PDgDf)(c),(-(*PDgDf)(c)*(*P_f)(c)+(*P_g)(c)));
}
/* ------------------------------------ */
void G_TanLy(
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"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " \"a_pts.plt\" with line lt 1,\\\n"
           " %0.6f*x %+0.6f,\\\n"
           " \"ayp.plt\" with linesp lt 3\n"
           " reset",
        W.xmini,W.xmaxi,W.ymini,W.ymaxi,
(*PDgDf)(c),(-(*PDgDf)(c)*(*P_f)(c)+(*P_g)(c)));
 fclose(fp);
 
        fp = fopen("a_pts.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("ayp.plt","w");
     fprintf(fp," %0.6f %0.6f\n",(*P_f)(c),(*P_g)(c));
     fprintf(fp,"    0. %0.6f \n",
     (*P_g)(c)- (*PDgDf)(c)*(*P_f)(c));
             fclose(fp);
}

Le résultat :

set zeroaxis
plot [-10.000:10.000] [-5.000:5.000] \
"a_pts.plt" with line lt 1,\
0.500000*x +1.414214,\
"ayp.plt" with linesp lt 3
reset

Conclusion

Application : Cercle de courbure


Préambule

Présentation

Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fb.h"
/* ------------------------------------ */
int main(void)
{
double t = PI;
double e = .001;
 
     circle("a_circle.plt",
               1./fabs(Kt_2d(f,g,t,e)),
                  cx_2d(f,g,t,e),
                  cy_2d(f,g,t,e));
 
     G_C_2d(i_WGnuplot(-4,8,-2,4),
            i_time(0.,2*PI,.03),
             f,g,t,
             e);
 
 printf(" The curvature K of a smooth parametric"
        " curve C is :\n\n\n"
 
        " K = |f' g'' - g' f''| / "
        "[ (f')^2 - (g')^2 ]^(3/2)\n\n"
 
        " If P(f(t),g(t)) is a point on the curve  \n"
        " at which K != 0. The point M(h,k)"
        " is the center\n"
        " of the cuvature for P if   \n\n\n"
        " h = f - g'[f'^2 + g'^2] / [f'g''-f''g']\n"
        " k = g + f'[f'^2 + g'^2] / [f'g''-f''g']\n\n\n"
 
        " The radius is r = 1/|K| \n\n\n"
 
        " Open the file \"a_main.plt\" with Gnuplot.\n\n");
 
 printf("\n Press return to continue");
 getchar();
 
 return 0;
}

Le résultat.

Résultat dans gnuplot
Résultat dans gnuplot
Résultat dans gnuplot

Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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    "xfx_x.h"
/* ------------------------------------ */
#include  "kradius.h"
#include     "kg_c.h"
#include  "kcircle.h"


Donné du cercle

/* ------------------------------------ */
/*  Save as :   kradius.h               */
/* ------------------------------------ */
double Kt_2d(
double (*P_f)(double t),
double (*P_g)(double t),
double t,
double e
)
{
double K;
double a;
double b;
 
a = fx_x((*P_f),t,e);
b = fx_x((*P_g),t,e);
 
K = fabs(a*fx_xx((*P_g),t,e)-b*fx_xx((*P_f),t,e))
                /
     pow(a*a+b*b,3./2.);
 
 return(K);
}
/* ------------------------------------ */
double cx_2d(
double (*P_f)(double t),
double (*P_g)(double t),
double t,
double e
)
{
double Num,Den;
 
 Num =( pow(fx_x((*P_f),t,e),2)
       +pow(fx_x((*P_g),t,e),2)
      )
      *fx_x((*P_g),t,e);
 
 Den = fx_x((*P_f),t,e)*fx_xx((*P_g),t,e)-
       fx_x((*P_g),t,e)*fx_xx((*P_f),t,e);
 
 return((*P_f)(t)-Num/Den);
}
/* ------------------------------------ */
double cy_2d(
double (*P_f)(double t),
double (*P_g)(double t),
double t,
double e
)
{
double Num,Den;
 
 Num =( pow(fx_x((*P_f),t,e),2)
       +pow(fx_x((*P_g),t,e),2)
      )
      *fx_x((*P_f),t,e);
 
 Den = fx_x((*P_f),t,e)*fx_xx((*P_g),t,e)-
       fx_x((*P_g),t,e)*fx_xx((*P_f),t,e);
 
 return((*P_g)(t)+Num/Den);
}

La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   fb.h                    */
/* ------------------------------------ */
double f(
double t)
{
        return( 4+sin(2*t) );
}
char  feq[] =  "4+sin(2*t)";
/* ------------------------------------ */
double g(
double t)
{
        return( 1-2*cos(3*t) );
}
char  geq[] =  "1-2*cos(3*t)";

La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_c.h                  */
/* ------------------------------------ */
void G_C_2d(
W_Ctrl W,
t_Ctrl T,
double (*P_f)(double x),
double (*P_g)(double x),
double x,
double e
)
{
FILE *fp;
double i;
 
        fp = fopen("a_main.plt","w");
fprintf(fp," reset\n"
           " set zeroaxis lt 8\n"
           " set size ratio -1\n"
           " set grid\n\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
           " \"a_radius.plt\" with linespoints,\\\n"
           " \"a_curve.plt\" with line,\\\n"
           " \"a_circle.plt\" with line\n",
           W.xmini,W.xmaxi,W.ymini,W.ymaxi);
 fclose(fp);
 
        fp = fopen("a_curve.plt","w");
for(i=T.mini; i =T.maxi; i+=T.step)
fprintf(fp," %6.3f  %6.3f\n",(*P_f)(i),(*P_g)(i));
fclose(fp);
 
        fp = fopen("a_radius.plt","w");
fprintf(fp," %6.5f   %6.5f\n",cx_2d((*P_f),(*P_g),x,e),
                              cy_2d((*P_f),(*P_g),x,e));
fprintf(fp," %6.5f   %6.5f\n",(*P_f)(x),(*P_g)(x));
             fclose(fp);
 
 Pause();
}

La fonction graphique: Le cercle

/* ------------------------------------ */
/*  Save as :   kcircle.h               */
/* ------------------------------------ */
void circle(
char   Name[FILENAME_MAX],
double r,
double x,
double y
)
{
FILE   *fp = fopen(Name,"w");
double   t = 0.;
 
for(;t 2.01*PI;t+=.1)
fprintf(fp," %6.5f %6.5f\n",r*cos(t)+x,r*sin(t)+y);
 fclose(fp);
}

Application : Courbe de Bézier


Préambule


Courbe de Béziers

Présentation

/* ------------------------------------ */
/*  Save as :  c01.c                    */
/* ------------------------------------ */
#include "x_ahfile.h"
/* ------------------------------------ */
int main(void)
{
 printf(" Une courbe de Bezier.\n\n");
 
    G_quadratic_Bezier_lp_2d(
             i_WGnuplot(-10,90,-10,50),
             i_point2d(20.,10.),
             i_point2d(40.,40.),
             i_point2d(60.,10.) );
 
 printf("\n\n load \"a_main.plt\" with gnuplot."
        "\n\n Press return to continue");
 
 return 0;
}


Résultat dans gnuplot


Une application


/* ------------------------------------ */
/*  Save as :  c02.c                    */
/* ------------------------------------ */
#include "x_ahfile.h"
/* ------------------------------------ */
int main(void)
{
 printf(" Une courbe de Bezier.\n\n");
 
    G_quadratic_Bezier_lp_2d(
             i_WGnuplot(-0,2,-0,1),
             i_point2d(0.,1.),
             i_point2d(1.,1.),
             i_point2d(1.,0.)  );
 
 printf("\n\n load \"a_main.plt\" with gnuplot."
        "\n\n Press return to continue");
 
 return 0;
}


Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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     "xspv.h"
/* ------------------------------------ */
#include    "kpoly.h"
#include  "kbezier.h"


Les équations de la courbe


/* ------------------------------------ */
/*  Save as :    kpoly.h                */
/* ------------------------------------ */
double quadratic_Bezier_x_2d(
double   t,
point2d P0,
point2d P1,
point2d P2
)
{
return(
    P0.x * pow((1-t),2) * pow(t,0) +
2 * P1.x * pow((1-t),1) * pow(t,1) +
    P2.x * pow((1-t),0) * pow(t,2)
);
}
/* ------------------------------------ */
double quadratic_Bezier_y_2d(
double   t,
point2d P0,
point2d P1,
point2d P2)
{
return(
    P0.y * pow((1-t),2) * pow(t,0) +
2 * P1.y * pow((1-t),1) * pow(t,1) +
    P2.y * pow((1-t),0) * pow(t,2)
);
}
/* ------------------------------------ */


La fonction graphique

/* ------------------------------------ */
/*  Save as :  kbezier.h                */
/* ------------------------------------ */
void G_quadratic_Bezier_lp_2d(
W_Ctrl   w,
point2d P0,
point2d P1,
point2d P2
)
{
FILE   *fp;
 
double  mini = 0.;
double  maxi = 1.;
double  step =  .01;
double     t = mini;
 
        fp = fopen("a_main.plt","w");
fprintf(fp," set zeroaxis lt 8\n"
           " set grid \n\n"
           " set size ratio -1\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " \"a_pts\" with linesp lt 3 pt 1, \\\n"
           " \"a_ctrlpt\" with linesp lt 4 pt 4 \\\n\n"
           " reset",w.xmini,w.xmaxi,w.ymini,w.ymaxi);
 fclose(fp);
 
             fp = fopen("a_pts","w");
 for(t=mini; t =maxi; t+=step)
     fprintf(fp," %6.5f   %6.5f\n",quadratic_Bezier_x_2d(t,P0,P1,P2),
                                   quadratic_Bezier_y_2d(t,P0,P1,P2));
      fclose(fp);
 
             fp = fopen("a_ctrlpt","w");
     fprintf(fp," %6.5f   %6.5f\n",P0.x,P0.y);
     fprintf(fp," %6.5f   %6.5f\n",P1.x,P1.y);
     fprintf(fp," %6.5f   %6.5f\n",P2.x,P2.y);
      fclose(fp);
 
 Pause();
}


Les sorties de la fonction :


set zeroaxis lt 8
set grid 
.
plot [-10.000:90.000] [-10.000:50.000] \
"a_pts" with linesp lt 3 pt 1, \
"a_ctrlpt" with linesp lt 4 pt 4 \
.
reset



Conclusion

Résultat dans gnuplot

Application : Courbe de Bézier rationnelle


Préambule


Courbes de Béziers rationelles (cubiques)


Présentation

/* ------------------------------------ */
/*  Save as :  c01.c                    */
/* ------------------------------------ */
#include "x_ahfile.h"
/* ------------------------------------ */
int main(void)
{
 
 printf(" Une courbe de Bezier.\n\n");
 
    G_quadratic_Bezier_lp_2d(
             i_WGnuplot(-10,90,-10,50),
             i_point2d(20.,10.),
             i_point2d(40.,40.),
             i_point2d(60.,10.)
             );
 
 printf("\n\n load \"a_main.plt\" with gnuplot."
        "\n\n Press return to continue");
 
 return 0;
}


Résultat dans gnuplot


Courbe du chapitre précédent


Une application


/* ------------------------------------ */
/*  Save as :  c02.c                    */
/* ------------------------------------ */
#include "x_ahfile.h"
/* ------------------------------------ */
int main(void)
{
 
 printf(" Une courbe de Bezier.\n\n");
 
    G_quadratic_Bezier_lp_2d(
             i_WGnuplot(-0,2,-0,1),
             i_point2d(0.,1.),
             i_point2d(1.,1.),
             i_point2d(1.,0.)
             );
 
 printf("\n\n load \"a_main.plt\" with gnuplot."
        "\n\n Press return to continue");
 
 return 0;
}


Résultat dans gnuplot


Courbe du chapitre précédent


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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     "xspv.h"
/* ------------------------------------ */
#include    "kpoly.h"
#include  "kbezier.h"


Les équations de la courbe

/* ------------------------------------ */
/*  Save as :    kpoly.h                */
/* ------------------------------------ */
double quadratic_Bezier_x_2d(
double   t,
point2d P0,
point2d P1,
point2d P2
)
{
return(
 
(
    P0.x * pow((1-t),2) * pow(t,0) +
2 * P1.x * pow((1-t),1) * pow(t,1) +
2 * P2.x * pow((1-t),0) * pow(t,2)
)
/
(
     pow((1-t),2) * pow(t,0) +
2 *  pow((1-t),1) * pow(t,1) +
2 *  pow((1-t),0) * pow(t,2)
)
 
);
}
/* ------------------------------------ */
double quadratic_Bezier_y_2d(
double   t,
point2d P0,
point2d P1,
point2d P2)
{
return( 
 
(
    P0.y * pow((1-t),2) * pow(t,0) +
2 * P1.y * pow((1-t),1) * pow(t,1) +
2 * P2.y * pow((1-t),0) * pow(t,2)
)
/
(
     pow((1-t),2) * pow(t,0) +
2 *  pow((1-t),1) * pow(t,1) +
2 *  pow((1-t),0) * pow(t,2)
) 
 
);
}
/* ------------------------------------ */


La fonction graphique

/* ------------------------------------ */
/*  Save as :  kbezier.h                */
/* ------------------------------------ */
void G_quadratic_Bezier_lp_2d(
W_Ctrl   w,
point2d P0,
point2d P1,
point2d P2
)
{
FILE   *fp;
 
double  mini = 0.;
double  maxi = 1.;
double  step =  .01;
double     t = mini;
 
        fp = fopen("a_main.plt","w");
fprintf(fp," set zeroaxis lt 8\n"
           " set grid \n\n"
           " set size ratio -1\n"
           " plot [%0.3f:%0.3f] [%0.3f:%0.3f] \\\n"
           " \"a_pts\" with linesp lt 3 pt 1, \\\n"
           " \"a_ctrlpt\" with linesp lt 4 pt 4 \\\n\n"
           " reset",w.xmini,w.xmaxi,w.ymini,w.ymaxi);
 fclose(fp);
 
        fp = fopen("a_pts","w");
 for(t=mini; t =maxi; t+=step)
     fprintf(fp," %6.5f   %6.5f\n",quadratic_Bezier_x_2d(t,P0,P1,P2),
                                   quadratic_Bezier_y_2d(t,P0,P1,P2));
 fclose(fp);
 
        fp = fopen("a_ctrlpt","w");
     fprintf(fp," %6.5f   %6.5f\n",P0.x,P0.y);
     fprintf(fp," %6.5f   %6.5f\n",P1.x,P1.y);
     fprintf(fp," %6.5f   %6.5f\n",P2.x,P2.y);
 fclose(fp);
 
 Pause();
}


Les sorties de la fonction :


set zeroaxis lt 8
set grid 
.
plot [-10.000:90.000] [-10.000:50.000] \
"a_pts" with linesp lt 3 pt 1, \
"a_ctrlpt" with linesp lt 4 pt 4 \
.
reset



Conclusion

Application : Fonction vectorielle 3D


Préambule

Présentation

Dessiner

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fa.h"
/* ------------------------------------ */
int main(void)
{
double t     =  4.;
 
 printf(" r(t) = f(t)i + g(t)j + h(t)k \n\n");
 printf(" With \n\n");
 printf(" f : t-  %s  \n", feq);
 printf(" g : t-  %s  \n", geq);
 printf(" h : t-  %s\n\n", heq);
 printf(" t = %+.2f \n\n",   t);
 
     G_Curve_3d(i_time(0.,6.*PI,.01),
                f,g,h,
                Tf,Tg,Th,
                t);
 
 printf(" Draw the velocity and accelerator vectors"
        " at the point P(f(t),g(t)),                \n\n"
        " open the file \"a_main.plt\" with Gnuplot.\n\n");
 
 printf("\n Press return to continue");
 getchar();
 
 return 0;
}

Le résultat.

Résultat dans gnuplot
Résultat dans gnuplot

Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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    "xfx_x.h"
/* ------------------------------------ */
#include   "knfx_x.h"
#include "kg_ctan1.h"


Normalisé

/* ------------------------------------ */
/*  Save as :   knfx_x.h                 */
/* ------------------------------------ */
double fx_x_Normalize(
double (*P_f)(double x),
double (*P_g)(double x),
double (*P_h)(double x),
double t,
double e
)
{
double Df=fx_x((*P_f),t,e);
double Dg=fx_x((*P_g),t,e);
double Dh=fx_x((*P_h),t,e);
 
 return(Df/sqrt(Df*Df+Dg*Dg+Dh*Dh));
}

La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   fa.h                    */
/* ------------------------------------ */
double f(
double t)
{
        return( cos(t));
}
char  feq[] =  "cos(t)";
/* ------------------------------------ */
double g(
double t)
{
        return( sin(t));
}
char  geq[] =  "sin(t)";
/* ------------------------------------ */
double h(
double t)
{
        return( t);
}
char  heq[] =  "t";
/* ------------------------------------ */
double Tf(
double t)
{
        return(
        -(sin(t)/sqrt(2))
        );
}
/* ------------------------------------ */
double Tg(
double t)
{
        return(
        cos(t)/sqrt(2)
        );
}
/* ------------------------------------ */
double Th(
double t)
{
        return(
        1/sqrt(2)
        );
}

La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_ctan1.h              */
/* ------------------------------------ */
void G_Curve_3d(
t_Ctrl T,
double (*P_f)(double t),
double (*P_g)(double t),
double (*P_h)(double t),
double (*P_Tf)(double t),
double (*P_Tg)(double t),
double (*P_Th)(double t),
double t
)
{
FILE *fp;
double i;
double e = .001;
 
fp = fopen("a_main.plt","w");
fprintf(fp," reset\n"
           " set zeroaxis lt 8\n"
           " set grid\n\n"
           " splot \\\n"
           " \"a_curve.plt\" with line lt 3,\\\n"
           " \"a_radius.plt\" with line lt 2,\\\n"
           " \"atangent.plt\" with line lt 4,\\\n"
           " \"anormal.plt\" with line lt 1 ");
fclose(fp);
 
        fp = fopen("a_curve.plt","w");
for(i=T.mini; i =T.maxi; i+=T.step)
fprintf(fp," %6.3f  %6.3f  %6.3f\n",
       (*P_f)(i),
       (*P_g)(i),
       (*P_h)(i));
 fclose(fp);
 
        fp = fopen("a_radius.plt","w");
fprintf(fp,"  0  0  0   \n %6.5f  %6.5f  %6.5f  \n",
       (*P_f)(t),
       (*P_g)(t),
       (*P_h)(t));
 fclose(fp);
 
        fp = fopen("atangent.plt","w");
fprintf(fp,"  %6.5f  %6.5f  %6.5f \n"
           "  %6.5f  %6.5f  %6.5f \n",
       (*P_f)(t),
       (*P_g)(t),
       (*P_h)(t),
       (*P_f)(t)+fx_x_Normalize((*P_f),(*P_g),(*P_h),t,e),
       (*P_g)(t)+fx_x_Normalize((*P_g),(*P_f),(*P_h),t,e),
       (*P_h)(t)+fx_x_Normalize((*P_h),(*P_f),(*P_g),t,e) );
 fclose(fp);
 
        fp = fopen("anormal.plt","w");
fprintf(fp,"  %6.5f  %6.5f  %6.5f \n"
           "  %6.5f  %6.5f  %6.5f \n",
       (*P_f)(t),
       (*P_g)(t),
       (*P_h)(t),
       (*P_f)(t)+fx_x_Normalize((*P_Tf),(*P_Tg),(*P_Th),t,e),
       (*P_g)(t)+fx_x_Normalize((*P_Tg),(*P_Tf),(*P_Th),t,e),
       (*P_h)(t)+fx_x_Normalize((*P_Th),(*P_Tf),(*P_Tg),t,e));
 fclose(fp);
 
 Pause();
}

Algorithme

r(t) = f(t) i + g(t) j + h(t) k
T(t) = r'(t) / ||r'(t)||
N(t) = T'(t) / ||T'(t)||

Application : Tangente de f(x,y)


Préambule


Présentation


Dessiner la tangente

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fa.h"
/* ------------------------------------ */
int main(void)
{
point2d p = i_point2d(1,2);
double  h = .001;
 
 printf(" Draw the equation of the tangent\n\n");
 printf(" at the point P(%.0f,%.0f),\n\n",p.x,p.y);
 printf(" on the plan x = %.0f for f(x,y).\n\n\n",p.x);
 printf(" f : (x,y)-  %s\n\n\n", feq);
 
 printf(" Cartesian form :\n\n"
        " z = %f y %+f\n\n",
        fxy_y(f,h,p),
        f(p.x,p.y)-fxy_y(f,h,p)*p.y);
 
       G_3d_p(i_WGnuplot(-10.,10.,-10.,10.),
              i_VGnuplot( 55.,57.,  1., 1.),
              feq,f,
              p);
 
 printf(" Open the file \"a_main.plt\" with gnuplot.\n");
 
 getchar();
 
 return 0;
}

Le résultat.


Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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     "xspv.h"
#include     "xplt.h"
#include   "xfxy_x.h"
/* ------------------------------------ */
#include    "kg_3d.h"


La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   fa.h                    */
/* ------------------------------------ */
double f(
double x,
double y)
{
 return( (9-x*x-y*y) );
}
char  feq[] = "9-x**2-y**2";


La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_3d.h                  */
/* ------------------------------------ */
void G_3d_p(
W_Ctrl W,
View_Ctrl V,
  char feq[],
double (*P_f)(double x, double y),
point2d p
)
{
FILE   *fp;
double a,b;
double    h = .001;
double step = 0.2;
 
        fp = fopen("a_main.plt","w");
fprintf(fp,"set isosamples 50\n"
           "set hidden3d\n"
           "set xlabel \"X axis\"\n"
           "set ylabel \"Y axis\"\n"
           "set zlabel \"Z axis\" offset 1, 0\n"
           "set view %0.3f, %0.3f, %0.3f, %0.3f \n"
           "splot[%0.3f:%0.3f][%0.3f:%0.3f]\\\n"
           "\"a_tan.plt\" with linesp lt 1 pt 3,\\\n"
           "\"a_p.plt\" pt 20,\\\n"
           "%s \n\n",
        V.rot_x,V.rot_z,V.scale,V.scale_z,
        W.xmini,W.xmaxi,W.ymini,W.ymaxi, feq);
 fclose(fp);
 
         fp = fopen("a_p.plt","w");
 fprintf(fp," %6.3f %6.3f %6.3f\n",
          p.x,p.y, (*P_f)(p.x,p.y));
  fclose(fp);
 
  a=fxy_y((*P_f),h,p);
  b=((*P_f)(p.x,p.y)-fxy_y((*P_f),h,p)*p.y);
 
  fp = fopen("a_tan.plt","w");
    for(p.y=W.ymini; p.y W.ymaxi;p.y+=step)
      fprintf(fp," %6.3f %6.3f %6.3f\n",
              p.x,p.y, a*p.y+b);
 fclose(fp);
 
  Pause();
}

Conclusion

Application : Gradient


Préambule


Présentation


Dessiner le gradient au point P

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fa.h"
/* ------------------------------------ */
int main(void)
{
double   h  = .0001;
 point2d p  = i_point2d(2,1);
vector2d u  = grad_fxy(g,h,p);
 
 clrscrn();
 printf(" Sketch both the level curve C of f "
        "that contains P and grad(P)   \n\n");
 printf(" f : (x,y)-  %s\n\n", feq);
 printf(" with p(%+.3f,%+.3f) \n\n",p.x,p.y);
 
  printf(" In first sketch the graph of f(x,y) = 0\n\n");
 
     G_3d_eq(i_WsGnuplot(-10,10,-10,10,-100,100),
             i_VGnuplot( 55.,57.,1.,1.),
             feq);
 
 printf(" Open the file \"a_main.plt\" with gnuplot.\n");
 getchar();
 
 clrscrn();
 printf(" The level curves have the form f(x,y) = k \n");
 printf(" with p(%+.3f,%+.3f) k = %+.3f \n\n",
          p.x,p.y,f(p.x,p.y));
 
 printf(" The new function is :\n");
 printf(" g : (x,y)-  %s\n\n", geq);
 
  printf(" grad(g)]p = %+.3fi  %+.3fj\n",u.i,u.j);
  printf(" is a vector normal to the function\n");
  printf(" g : (x,y)-  %s\n", geq);
  printf(" at the point p(%+.3f,%+.3f)\n\n", p.x,p.y);
 
  G_3d_levelcurvegradfxy(i_WsGnuplot(-6,6,-6,6,
                                    g(p.x,p.y),
                                    g(p.x,p.y)+.1),
                         g,geq,
                         p);
 
 printf(" Open the file \"a_main.plt\" with gnuplot.\n"
        " Press return to continue.\n");
 
 getchar();
 
 return 0;
}

Le résultat.


Sketch both the level curve C of f  that contains P and grad(P)    
.
f : (x,y)-   y**2-x**2
.
with p(+2.000,+1.000) 
.
In first sketch the graph of f(x,y) = 0
.
Open the file "a_main.plt" with gnuplot.
Résultat dans gnuplot
The level curves have the form f(x,y) = k 
with p(+2.000,+1.000) k = -3.000 
.
The new function is :
g : (x,y)-   y**2-x**2+3
.
grad(g)]p = -4.000i  +2.000j
is a vector normal to the function
g : (x,y)-   y**2-x**2+3
at the point p(+2.000,+1.000)
.
Open the file "a_main.plt" with gnuplot.
Press return to continue.
Résultat dans gnuplot


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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     "xspv.h"
#include     "xplt.h"
#include   "xfxy_x.h"
/* ------------------------------------ */
#include    "kgrad.h"
#include    "kg_3d.h"
#include  "kg_grad.h"


La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   fa.h                   */
/* ------------------------------------ */
double f(
double x,
double y)
{
 return( ( y*y-x*x) );
}
char  feq[] = " y**2-x**2";
/* ------------------------------------ */
double g(
double x,
double y)
{
 return( ( y*y-x*x+3) );
}
char  geq[] = " y**2-x**2+3";
/* ------------------------------------ */


Le gradient.

/* ------------------------------------ */
/*  Save as :   kgrad.h                 */
/* ------------------------------------ */
vector2d grad_fxy(
double (*P_f)(double x,double y),
double   h,
point2d  p
)
{
vector2d   u;
 
       u.i = fxy_x((*P_f),h,p);
       u.j = fxy_y((*P_f),h,p);
 
 return(u);
}


La fonction graphique (1)

/* ------------------------------------ */
/*  Save as :   kg_3d.h                 */
/* ------------------------------------ */
void G_3d_eq(
   Ws_Ctrl W,
View_Ctrl V,
char      feq[]
)
{
FILE   *fp = fopen("a_main.plt","w");
fprintf(fp,"reset\n"
           "set    samples 40\n"
           "set isosamples 40\n"
           "set hidden3d\n"
           "set view %0.3f, %0.3f, %0.3f, %0.3f \n"
           "splot[%0.3f:%0.3f][%0.3f:%0.3f][%0.3f:%0.3f]\\\n"
           "%s",
            V.rot_x,V.rot_z,V.scale,V.scale_z,
            W.xmini,W.xmaxi,W.ymini,W.ymaxi,W.zmini,W.zmaxi,
            feq);
 fclose(fp);
}

La fonction graphique (2)

/* ------------------------------------ */
/*  Save as :   kg_grad.h               */
/* ------------------------------------ */
void G_3d_levelcurvegradfxy(
Ws_Ctrl W,
double (*P_f)(double x, double y),
char    feq[],
point2d   p
)
{
FILE   *fp;
double   h  = .0001;
 
        fp = fopen("a_main.plt","w");
fprintf(fp,"reset\n"
           "set    samples 400\n"
           "set isosamples 400\n"
           "set view 1.000, 1.000, 1.000, 1.000 \n"
           "splot[%0.3f:%0.3f][%0.3f:%0.3f][%0.3f:%0.3f]\\\n"
           "%s,\\\n"
           "\"a_vect\" with linesp lt 3\n",
           W.xmini,W.xmaxi,W.ymini,W.ymaxi,W.zmini,W.zmaxi,
           feq);
 fclose(fp);
 
 fp = fopen("a_vect","w");
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
                 p.x, p.y, ((*P_f)(p.x,p.y)) );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
                 p.x+fxy_x((*P_f),h,p),
                 p.y+fxy_y((*P_f),h,p),
                   (*P_f)(p.x,p.y) );
 fclose(fp);
}


Conclusion

Application : Vecteur normal


Préambule


Présentation


Dessiner le vecteur normale au point P

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fa.h"
/* ------------------------------------ */
int main(void)
{
   printf(" Draw the normal vector at the point P.\n\n"
          " f : (x,y)-  %s\n\n", feq);
 
     G_3d_v(i_WsGnuplot(-3,3,-3,3,-.5,2),
            i_VGnuplot( 94.,22.,1.,1.),
            feq,f,f_z,
            i_point2d(1,0.));
 
 printf(" Open the file \"a_main.plt\" with gnuplot.\n"
        " Press return to continue.\n");
 getchar();
 
 return 0;
}

Le résultat.

Résultat dans gnuplot

Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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     "xspv.h"
#include  "xfxyz_x.h"
/* ------------------------------------ */
#include   "kg_3dv.h"


La fonction à dessiner

/* ------------------------------------ */
/*  Save as :  fa.h                     */
/* ------------------------------------ */
double f(
double x,
double y)
{
 return(      (2*exp(-x) * cos(y)) );
}
char  feq[] = "2*exp(-x) * cos(y)";
/* ------------------------------------ */
double f_z(
double x,
double y,
double z)
{
 return(      (2*exp(-x) * cos(y) - z) );
}
char  f_zeq[] = "2*exp(-x) * cos(y) - z";


La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_3dv.h                */
/* ------------------------------------ */
void G_3d_v(
  Ws_Ctrl W,
View_Ctrl V,
  char feq[],
double (*P_f) (double x, double y),
double (*P_fz)(double x, double y, double z),
point2d p
)
{
FILE   *fp;
point3d p3d = i_point3d(p.x,p.y,(*P_f)(p.x,p.y));
 
        fp = fopen("a_main.plt","w");
fprintf(fp,"reset\n"
           "set    samples 40\n"
           "set isosamples 40\n"
           "set hidden3d\n"
           "set view %0.3f, %0.3f, %0.3f, %0.3f \n"
           "splot[%0.3f:%0.3f][%0.3f:%0.3f][%0.3f:%0.3f]\\\n"
           "\"a_ka.plt\" with linespoints,\\\n"
           "%s ",
            V.rot_x,V.rot_z,V.scale,V.scale_z,
            W.xmini,W.xmaxi,W.ymini,W.ymaxi,W.zmini,W.zmaxi,
            feq);
 fclose(fp);
 
 fp = fopen("a_ka.plt","w");
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x, p.y, ((*P_f)(p.x,p.y)) );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x-fxyz_x((*P_fz),0.0001,p3d),
              p.y-fxyz_y((*P_fz),0.0001,p3d),
((*P_f)(p.x,p.y))-fxyz_z((*P_fz),0.0001,p3d));
 fclose(fp);
 
Pause();
}


Conclusion

Application : Plan tangent


Préambule


Présentation

Dessiner le plan tangent au point P

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include       "fa.h"
/* ------------------------------------ */
int main(void)
{
 
 printf(" Draw the Tangent plane.\n\n"
        " f : (x,y)-  %s\n\n", feq);
 
     G_3d_v( i_WsGnuplot(-4,4,-4,4,-1,2),
             i_VGnuplot( 80.,38.,1.,1.),
             feq,f,f_z,
             i_point2d(2,0.));
 
 printf(" Open the file \"a_main.plt\" with gnuplot.\n"
        " Press return to continue.\n");
 getchar();
 
 return 0;
}

Le résultat.

Résultat dans gnuplot

Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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     "xspv.h"
#include     "xplt.h"
#include  "xfxy_x.h"
#include  "xfxyz_x.h"
/* ------------------------------------ */
#include    "kg_3d.h"


La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   fa.h                    */
/* ------------------------------------ */
double f(
double x,
double y)
{
 return(       cos(x)+cos(y) );
}
char  feq[] = "cos(x)+cos(y)";
/* ------------------------------------ */
double f_z(
double x,
double y,
double z)
{
 return(         cos(x)+cos(y)-z );
}
char  f_zeq[] = "cos(x)+cos(y)-z";


La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_3d.h                 */
/* ------------------------------------ */
void G_3d_v(
  Ws_Ctrl W,
View_Ctrl V,
  char feq[],
double (*P_f) (double x, double y),
double (*P_fz)(double x, double y, double z),
point2d p
)
{
FILE      *fp;
point3d   P3D = i_point3d(p.x,p.y,(*P_f)(p.x,p.y));
double radius = .5;
 
        fp = fopen("a_main.plt","w");
fprintf(fp,"reset\n"
           "set size ratio -1\n"
           "set    samples 40\n"
           "set isosamples 40\n"
           "set hidden3d\n"
           "set view %0.3f, %0.3f, %0.3f, %0.3f \n"
           "splot[%0.3f:%0.3f][%0.3f:%0.3f][%0.3f:%0.3f]\\\n"
           " \"a_ka.plt\" with linesp lt 1 lw 4,\\\n"
           " \"a_kb.plt\" with linesp lt 1 lw 4 ps 2,\\\n"
           "%s lt 3",
            V.rot_x,V.rot_z,V.scale,V.scale_z,
            W.xmini,W.xmaxi,W.ymini,W.ymaxi,W.zmini,W.zmaxi,
            feq);
 fclose(fp);
 
 fp = fopen("a_ka.plt","w");
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x, p.y, (*P_f)(p.x,p.y) );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x-fxyz_x((*P_fz),0.0001,P3D),
              p.y-fxyz_y((*P_fz),0.0001,P3D),
((*P_f)(p.x,p.y))-fxyz_z((*P_fz),0.0001,P3D));
 fclose(fp);
 
 fp = fopen("a_kb.plt","w");
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x+radius,
              p.y+radius,
              fxy_x((*P_f),0.0001,p)*(+radius)+
              fxy_y((*P_f),0.0001,p)*(+radius)+
              (*P_f)(p.x,p.y)
              );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x-radius,
              p.y+radius,
              fxy_x((*P_f),0.0001,p)*(-radius)+
              fxy_y((*P_f),0.0001,p)*(+radius)+
              (*P_f)(p.x,p.y)
              );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x-radius,
              p.y-radius,
              fxy_x((*P_f),0.0001,p)*(-radius)+
              fxy_y((*P_f),0.0001,p)*(-radius)+
              (*P_f)(p.x,p.y)
              );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x+radius,
              p.y-radius,
              fxy_x((*P_f),0.0001,p)*(+radius)+
              fxy_y((*P_f),0.0001,p)*(-radius)+
              (*P_f)(p.x,p.y)
              );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x+radius,
              p.y+radius,
              fxy_x((*P_f),0.0001,p)*(+radius)+
              fxy_y((*P_f),0.0001,p)*(+radius)+
              (*P_f)(p.x,p.y)
              );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x-radius,
              p.y-radius,
              fxy_x((*P_f),0.0001,p)*(-radius)+
              fxy_y((*P_f),0.0001,p)*(-radius)+
              (*P_f)(p.x,p.y)
              );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x+radius,
              p.y-radius,
              fxy_x((*P_f),0.0001,p)*(+radius)+
              fxy_y((*P_f),0.0001,p)*(-radius)+
              (*P_f)(p.x,p.y)
              );
         fprintf(fp," %6.3f   %6.3f   %6.3f\n",
              p.x-radius,
              p.y+radius,
              fxy_x((*P_f),0.0001,p)*(-radius)+
              fxy_y((*P_f),0.0001,p)*(+radius)+
              (*P_f)(p.x,p.y)
              );
 fclose(fp);
 
 Pause();
}


Conclusion

Commande pause 1


Préambule

Présentation


Le cadre

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include  "kg_tan1.h"
/* ------------------------------------ */
int main(void)
{
t_Ctrl Pic = {0,5,1};
 
  G_TanA(Pic);
 
 printf(" Read \"a_main.plt\".\n\n"
        " Press return to continue");
 getchar();
 
 return 0;
}

Le résultat.

set zeroaxis
.
pause 1
.
pause 1
.
pause 1
.
pause 1
.
pause 1
.
reset


Dessiner

/* ------------------------------------ */
/*  Save as :   c02.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include  "kg_tan2.h"
#include       "f2.h"
/* ------------------------------------ */
int main(void)
{
 printf("  f : x-  %s  \n", feq);
 
  G_TanA(i_WGnuplot(-7, 7,-2,2),
         i_time(0,5,1),
         feq);
 
 printf(" load \"a_main.plt\" with gnuplot. \n\n"
        " Press return to continue");
 getchar();
 
 return 0;
}

Le résultat.

set zeroaxis
.
plot [-7.000:7.000] [-2.000:2.000]   cos(x)
pause 1
.
plot [-7.000:7.000] [-2.000:2.000]   cos(x)
pause 1
.
plot [-7.000:7.000] [-2.000:2.000]   cos(x)
pause 1
.
plot [-7.000:7.000] [-2.000:2.000]   cos(x)
pause 1
.
plot [-7.000:7.000] [-2.000:2.000]   cos(x)
pause 1
.
reset

Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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"


La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   f2.h                    */
/* ----------- f ---------------------- */
double f(
double x)
{
 return(       cos(x));
}
char  feq[] = " cos(x)";

La fonction graphique pour c01.c

/* ------------------------------------ */
/*  Save as :   kg_tan1.h               */
/* ------------------------------------ */
void G_TanA(
t_Ctrl Pic
)
{
FILE *fp = fopen("a_main.plt","w");
double p;
 
    fprintf(fp," set zeroaxis\n\n");
 
for(p=Pic.mini; p Pic.maxi; p+=Pic.step)
 
    fprintf(fp," pause 1\n\n");
 
    fprintf(fp," reset");
     fclose(fp);
}

La fonction graphique pour c02.c

/* ------------------------------------ */
/*  Save as :   kg_tan2.h                */
/* ------------------------------------ */
void G_TanA(
W_Ctrl w,
t_Ctrl Pic,
char   fEQ[]
)
{
FILE *fp = fopen("a_main.plt","w");
double p ;
 
    fprintf(fp," set zeroaxis\n\n");
 
for(p = Pic.mini; p Pic.maxi; p+=Pic.step)
 
    fprintf(fp," plot [%0.3f:%0.3f] [%0.3f:%0.3f] "
               " %s\n"
               " pause 1\n\n",
                 w.xmini,w.xmaxi,w.ymini,w.ymaxi,
                 fEQ);
 
    fprintf(fp," reset");
     fclose(fp);
}

Animer un point


Préambule


Présentation


L'animation

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include        "f.h"
/* ------------------------------------ */
int main(void)
{
    G_plt(i_WGnuplot(-5,5, -1,10),
          i_time(-3.,5., .01),
          feq,f);
 
 printf(" open the file \"a_main.plt\" with Gnuplot.\n\n"
        " Press return to continue\n");
 getchar();
 
 return 0;
}

Le résultat.

reset
plot[-5.000:5.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paab" pt 7 ps 3 
reset
plot[-5.000:5.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paac" pt 7 ps 3 
reset
plot[-5.000:5.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paad" pt 7 ps 3 
reset
plot[-5.000:5.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paae" pt 7 ps 3 
reset
plot[-5.000:5.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paaf" pt 7 ps 3 


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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_f.h"


La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   f.h                     */
/* ------------------------------------ */
double f(
double x)
{
 return(       -0.5*x*x  + 1.0*x + 8.0);
}
char  feq[] = "-0.5*x**2 + 1.0*x + 8.0";


La fonction graphique

/* ------------------------------------ */
/*  Save as :   kg_f.h                  */
/* ------------------------------------ */
void G_plt(
W_Ctrl w,
t_Ctrl Pic,
char feq[],
double (*P_f)(double x)
)
{
FILE   *fp1;
FILE   *fp2;
double    p;
char files[]= "a_paaa";
 
         fp1 = fopen("a_main.plt","w");
 
for(p=Pic.mini; p Pic.maxi; p+=Pic.step)
{
 fprintf(fp1," reset\n"
            " plot[%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
            " %s lt 13,\\\n"
            " \"%s\" pt 7 ps 3 \n",
         w.xmini,w.xmaxi,w.ymini,w.ymaxi,
         feq,
         NewName(files));
 
         fp2 = fopen(files,"w");
 fprintf(fp2," %+0.6f %+0.6f",p,(*P_f)(p));
  fclose(fp2);
}
  fclose(fp1);
}

Animer deux points


Préambule

Présentation


L'animation

/* ------------------------------------ */
/*  Save as :   c01.c                   */
/* ------------------------------------ */
#include "x_ahfile.h"
#include        "f.h"
/* ------------------------------------ */
int main(void)
{
    G_plt(i_WGnuplot(-5,5, -1,10),
          i_time(-3.,5., .01),
          feq,f);
 
 printf(" open the file \"a_main.plt\" with Gnuplot.\n\n"
        " Press return to continue\n");
 getchar();
 
 return 0;
}

Le résultat.

reset
plot[-4.000:6.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paab"  pt 7 ps 3 
reset
plot[-4.000:6.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paac"  pt 7 ps 3 
reset
plot[-4.000:6.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paad"  pt 7 ps 3 
reset
plot[-4.000:6.000] [-1.000:10.000]\
-0.5*x**2 + 1.0*x + 8.0 lt 13,\
"a_paae"  pt 7 ps 3 


Les fichiers h de ce chapitre

Appel des fichiers standards

/* ------------------------------------ */
/*  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_f.h"


La fonction à dessiner

/* ------------------------------------ */
/*  Save as :   f.h                     */
/* ------------------------------------ */
double f(
double x)
{
 return(       -0.5*x*x  + 1.0*x + 8.0);
}
char  feq[] = "-0.5*x**2 + 1.0*x + 8.0";

La fonction graphique

/* ------------------------------------ */
/*  Save as :   xg_f.h                  */
/* ------------------------------------ */
void  G_plt(
W_Ctrl w,
t_Ctrl Pic,
char feq[],
double (*P_f)(double x)
)
{
FILE   *fp1;
FILE   *fp2;
double  p,q;
char files[] = "a_paaa";
 
        fp1 = fopen("a_main.plt","w");
 
for(p=q=Pic.mini; p Pic.maxi; p+=Pic.step)
{
 fprintf(fp1," reset\n"
             " plot[%0.3f:%0.3f] [%0.3f:%0.3f]\\\n"
             " %s lt 13,\\\n"
             " \"%s\"  pt 7 ps 3 \n",
             w.xmini,w.xmaxi,w.ymini,w.ymaxi,
             feq,
             NewName(files));
 
         fp2 = fopen(files,"w");
 fprintf(fp2," %+0.6f %+0.6f\n",p,(*P_f)(p));
 fprintf(fp2," %+0.6f %+0.6f\n",q,(*P_f)(p));
  fclose(fp2);
}
 fclose(fp1);
}

Animation : Tangente


Préambule


Présentation


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 <
      
© Copyright Wikipedia authors - The articles gathered in this document are under the GFDL licence.
http://www.gnu.org/copyleft/fdl.html