Mathc gnuplot/Application : Tangente de P à l'axes des y d'une courbe
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(f(c),g(c) à l'axe de y. |
---|
/* ------------------------------------ */
/* 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
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 "xdef.h"
#include "xplt.h"
/* ------------------------------------ */
#include "kg_tan.h"
fe.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));
}
kg_tan.h 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);
}