Sommaire


Les fonctions f‘

modifier

Calculer la dérivée première.

  c00.c
/* ------------------------------ */
/* Save as c00.c                  */
/* ------------------------------ */
#include    <stdio.h>
#include     <math.h>

/* ------------------------------ */
double f(
double x)
{return( pow(x,2.));}
/* ------------------------------ */
char  feq[] = "x**2";
/* ------------------------------ */
/* ------------------------------ */

/* ------------------------------ */
double g(
double x)
{return(pow(cos(x),2.)+sin(x)+x-3);}
/* ------------------------------ */
char  geq[] = "cos(x)**2+sin(x)+x-3";
/* ------------------------------*/
/* ------------------------------*/

/* ------------------------------
 f'(a) = f(a+h) - f(a-h)
          -------------
              2h
   ------------------------------ */
double Dx_1(
double (*P_f)(double x),
double a,
double h
)
{
 return( ( ((*P_f)(a+h))-((*P_f)(a-h)) ) / (2.*h) );
}
/* ------------------------------*/
int main(void)
{
double x = 2.;
double h = 0.001;

printf("\n\n");

printf(" f : -> %s\n\n",feq);
printf("  f(%.3f) = %.3f  \n",x,f(x)       );
printf(" f'(%.3f) = %.3f  \n",x,Dx_1(f,x,h));

printf("\n\n");

printf(" g : -> %s\n\n",geq);
printf("  g(%.3f) = %.3f \n",x,g(x)       );
printf(" g'(%.3f) = %.3f \n",x,Dx_1(g,x,h));

printf("\n\n Press return to continue.");
getchar();

 return 0;
}
/* ------------------------------*/
/* ------------------------------*/


Exemple de sortie écran :

 f : -> x**2

  f(2.000) = 4.000  
 f'(2.000) = 4.000  


 g : -> cos(x)**2+sin(x)+x-3

  g(2.000) = 0.082 
 g'(2.000) = 1.341 


 Press return to continue.