« Mathc gnuplot/Pointeurs de fonctions » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 73 :
#include <stdio.h>
#include <math.h>
/* ------------------------------ */
 
/* ------ Fonction f ------------ */
double f(double x){return( pow(x,2.));}
/* ------------------------------ */
char feq[] = "x**2";
/* ------------------------------ */
/* ------ Fonction g ------------ */
double g(double x){return(
Ligne 85 ⟶ 82 :
/* ------------------------------ */
char geq[] = "cos(x)**2+sin(x)+x-3";
/* ------------------------------ */
 
 
/* ------------------------------
f'(a) = f(a+h) - f(a-h)
Ligne 114 ⟶ 108 :
return( (((*P_f)(a+h))-2*((*P_f)(a))+((*P_f)(a-h))) / (h*h) );
}
 
 
/* ------------------------------ */
int main(void)
Ligne 166 ⟶ 158 :
#include <stdio.h>
#include <math.h>
/* ------------------------------ */
 
 
/* ------ Fonction f ------------ */
double f(double x){return( pow(x,2.));}
/* ------------------------------ */
char feq[] = "x**2";
/* ------------------------------ */
 
/* ------ Fonction g ------------ */
double g(double x){return(2.0*x + 3.0);}
/* ------------------------------ */
char geq[] = "2.0*x + 3.0";
/* ------------------------------ */
 
 
/* - Fonction FoG (g suivie de f)-*/
double FoG(
Ligne 191 ⟶ 175 :
return((*P_F)( ((*P_G)(a))) );
}
/* ------------------------------ */
 
 
/* ------------------------------ */
int main(void)
Ligne 202 ⟶ 183 :
printf(" g : x-> %s\n", geq);
printf(" \n\n");
 
 
printf(" f(g(%.0f)) = %6.1f\n", a, FoG(f,g,a));
printf(" g(f(%.0f)) = %6.1f\n", a, FoG(g,f,a));
printf(" f(f(%.0f)) = %6.1f\n", a, FoG(f,f,a));
 
 
printf("\n\n Press return to continue.\n");
Ligne 246 ⟶ 225 :
#include <math.h>
/* ------------------------------ */
 
/* --- Dessinons f et g --------- */
double f(double x){return( pow(x,2.));}
double g(double x){return(2.0*x + 3.0);}
/* ------------------------------ */
 
 
/* Le fichier de points: [a,f(a)] */
void G_plt(
double (*P_f)(double x)
Ligne 267 ⟶ 241 :
fclose(fp);
}
 
 
/* ------------------------------ */
int main(void)
{
 
printf("Pour dessiner f. Dans gnuplot -> plot \"data\" ");
G_plt(f);
Ligne 279 ⟶ 250 :
printf("Pour dessiner g. Dans gnuplot -> plot \"data\" ");
G_plt(g);
 
 
printf("\n\n Press return to continue.\n");
Ligne 291 ⟶ 261 :
=== Solution pour le chapitre précédent ===
* La fonction G_plot() dessine f(x) et g(x)la chaîne de caractères...
 
 
Ligne 298 ⟶ 268 :
#include <stdio.h>
#include <math.h>
/* ------------------------------ */
 
/* ------------------------------ */
double f(double x){return(cos(x));}
char feq[] = "cos(x)";
/* ------------------------------ */
 
/* ------------------------------ */
double g(double x){return(sin(x));}
char geq[] = "sin(x)";
/* ------------------------------ */
 
 
/* ------------------------------ */
int G_plot(
Ligne 319 ⟶ 282 :
char datafile[]="data";
double a;
 
 
if (!(fp = fopen(datafile,"w")))
Ligne 327 ⟶ 289 :
a,((*P_f)(a)));
fclose(fp);
 
 
 
if (!(fp = fopen("a_main.plt","w")))
Ligne 343 ⟶ 303 :
return 0;
}
/* ------------------------------ */
 
/* ------------------------------ */
int main(void)
Ligne 354 ⟶ 312 :
printf("Pour dessiner g. Dans gnuplot: load \"a_main.plt\" ");
G_plot(g,geq);
 
 
printf("\n\n Press return to continue.\n");