Mathc gnuplot/Application : Tangente de P à l'axes des y
Préambule
modifierLa tangente dans Wikipedia.
Présentation
modifierN'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.
Dessiner
modifierc01.c Calculer la longeur de P(c,f(c) à l'axe de y. |
---|
/* ------------------------------------ */
/* 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
modifierx_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_TanPy(
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\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);
fp = fopen("a_yaxe.plt","w");
fprintf(fp," %0.5f %0.5f\n",c,((*P_f)(c)));
fprintf(fp," 0.000 %0.5f",
((*P_f)(c))-(((*PDf)(c))*c));
fclose(fp);
}
Même exemple avec la fonction sin.
Résultat dans gnuplot |
---|