Mathc gnuplot/Application : Tangente de P à l'axes des x
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 x. |
---|
/* ------------------------------------ */
/* 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
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_TanPx(
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,"# Gnuplot file : load \"a_main.plt\" \n\n"
" 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);
fp = fopen("a_xaxe.plt","w");
fprintf(fp," %0.6f %0.6f\n",c,(*P_f)(c) );
fprintf(fp," %0.6f 0. \n",
c-((*P_f)(c)/(*PDf)(c)));
fclose(fp);
}
Même exemple avec la fonction sin.
Résultat dans gnuplot |
---|