Mathc initiation/Fichiers h : x 19c1c

Un livre de Wikilivres.
Aller à la navigation Aller à la recherche

Sommaire

Installer et compiler ces fichiers dans votre répertoire de travail.

Crystal Clear mimetype source c.png c1c.c
'
/* ---------------------------------- */
/* save as c1c.c                      */
/* ---------------------------------- */
#include "x_hfile.h"
#include      "fc.h"
/* --------------------------------- */
int main(void)
{
double (*P_f)(double x, double y);

double                  n;
double                  a;
double                  b;
double                 y0;

 P_f = Yp;
   n =       10.0;
   a =        0.0;
   b =        2.0;
  y0 =       -1.5;

 clrscrn();
 
 printf(" Euler's method to approximate the solution\n" 
        " of the differential equation.\n\n" 
        "  y' = %s\n\n",Ypeq);

 p_Euler_s_Method(a,
                        b,
                        n,
                        y0,
                        (*P_f));

 printf("                    y_n = %.10f\n\n",
         Euler_s_Method(a,
                        b,
                        n,
                        y0,
                        (*P_f))
        );

 printf(" The exact value is y   = -1.012136331\n\n");

 stop();
 
 
 clrscrn();
 
 n = 10000000.0;
  
 printf(" Euler's method to approximate the solution\n" 
        " of the differential equation\n\n" 
        "  y' = %s,\n\n with n = %.0f \n\n",Ypeq, n);


 printf("                    y_n = %.10f\n\n",
         Euler_s_Method(a,
                        b,
                        n,
                        y0,
                        (*P_f))
        );

 printf(" The exact value is y   = -1.012136331\n\n");

 stop();
 return 0;
}


Calculons la solution numérique de l'équation

y' = -(y+1)*(y+3)  pour 0 < x <  2
avec comme condition initial y0 = -1.5 quand x = 0


Exemple de sortie écran 1 :

 Euler's method to approximate the solution
 of the differential equation.

  y' = -(y+1)*(y+3)

  k  | x_k   | y_k         
 --------------------------
   1 | 0.200 | -1.3500000000
   2 | 0.400 | -1.2345000000
   3 | 0.600 | -1.1516980500
   4 | 0.800 | -1.0956212897
   5 | 1.000 | -1.0592014600
   6 | 1.200 | -1.0362218386
   7 | 1.400 | -1.0219955075
   8 | 1.600 | -1.0132940649
   9 | 1.800 | -1.0080117854
  10 | 2.000 | -1.0048199090


                    y_n = -1.0048199090

 The exact value is y   = -1.012136331

 Press return to continue.


Exemple de sortie écran : 2

  
 Euler's method to approximate the solution
 of the differential equation

  y' = -(y+1)*(y+3),

 with n = 10000000 

                    y_n = -1.0121363227

 The exact value is y   = -1.012136331

 Press return to continue.