Mathc gnuplot/Application : Tangente de P à l'axes des x d'une courbe
Apparence
Préambule
[modifier | modifier le wikicode]La tangente dans Wikipedia.
Présentation
[modifier | modifier le wikicode]N'oubliez pas les fichiers *.h partagés et ceux de ce chapitre.
Dessiner
[modifier | modifier le wikicode]c01.c Calculer la longeur de P(f(c),g(c) à l'axe de x. |
---|
/* ------------------------------------ */
/* 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
[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 "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_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);
}