Aller au contenu

Mathc gnuplot/Application : Sous tangente

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

I - Dessiner

Fichiers h partagés :

Application :

II - Animer

Application :

III - Géométrie de la tortue standard

Application :

IV - Géométrie de la tortue vectorielle

Application :

Annexe


La tangente dans Wikipedia.

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

c01.c
Calculer la longeur de la sous tangente.
/* ------------------------------------ */
/*  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
Tangente09


Les fichiers h de ce chapitre

[modifier | modifier le wikicode]
x_ahfile.h
Appel des fichiers
/* ------------------------------------ */
/*  Save as :   x_ahfile.h              */
/* ------------------------------------ */
#include    <stdio.h>
#include   <stdlib.h>
#include    <ctype.h>
#include     <time.h>
#include     <math.h>
#include   <string.h>
/* ------------------------------------ */
#include     "xplt.h"
/* ------------------------------------ */
#include   "kg_tan.h"
#include    "k_tan.h"


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


k_tan.h
Equation de la tangente
/* ------------------------------------ */
/*  Save as :    k_tan.h                */
/* ------------------------------------
   y = ax + b    [P(xp,yp);(y-yp)=a(x-xp)]


   a = f'(x)

   b = y - ax
   b = y - f'(x)x
   b = f(x) - f'(x)x

   x=c
   a = f'(c)
   b = f(c) - f'(c)c
   ------------------------------------ */
void eq_Tan(
double    c,
double (*P_f)(double x),
double (*PDf)(double x)
)
{
 printf(" %0.3f*x %+0.3f\n\n\n", 
 (*PDf)(c), (*P_f)(c) - (*PDf)(c)*c );
}
/* ------------------------------------ */
void eq_Tanf(
FILE *fp,
double    c,
double (*P_f)(double x),
double (*PDf)(double x)
)
{
fprintf(fp," %0.3f*x %+0.3f\n\n\n", 
 (*PDf)(c), (*P_f)(c) - (*PDf)(c)*c );
}


kg_tan.h
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;

        fp = fopen("a_main.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);

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

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


Même exemple avec la fonction sin.

Résultat dans gnuplot
Tangente10