Aller au contenu

Mathc initiation/Fichiers h : x 20c1b

Un livre de Wikilivres.

Sommaire

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

c1b.c
/* ---------------------------------- */
/* save as c1b.c                      */
/* ---------------------------------- */
#include "x_hfile.h"
#include      "fb.h"
/* --------------------------------- */
int main(void)
{
double                  n;
double                  a;
double                  b;
double                 y0;

   n =       10.0;
   a =        1.0;
   b =        2.0;
  y0 =        3.0;
  
 clrscrn();
 
 printf(" Heun's method to approximate the solution\n" 
        " of the differential equation.\n\n" 
        "  y' = %s\n\n",Ypeq);

 p_Heun_s_Method(a,
                        b,
                        n,
                        y0,
                        Yp);

 printf("                    y_n = %.10f\n\n",
          Heun_s_Method(a,
                        b,
                        n,
                        y0,
                        Yp)
        );

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

 stop();
 
 
 clrscrn();
 
 n = 100.0;
  
 printf(" Heun'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",
          Heun_s_Method(a,
                        b,
                        n,
                        y0,
                        Yp)
        );

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

 stop();
 return 0;
}
/* ---------------------------------- */
/* ---------------------------------- */


Calculons la solution numérique de l'équation

y' = 1 + y/x  pour 1 < x <  2
avec comme condition initial y0 = 3. quand x = 1


Exemple de sortie écran 1 :

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

  y' = 1 + y/x

  k  | x_k   | y_k         
 --------------------------
   1 | 1.100 | 3.4045454545
   2 | 1.200 | 3.8182162534
   3 | 1.300 | 4.2402470951
   4 | 1.400 | 4.6699913771
   5 | 1.500 | 5.1068955231
   6 | 1.600 | 5.5504802246
   7 | 1.700 | 6.0003264152
   8 | 1.800 | 6.4560645703
   9 | 1.900 | 6.9173664031
  10 | 2.000 | 7.3839383191
                    y_n = 7.3839383191

 The exact value is y   = 7.38629

 Press return to continue.


Exemple de sortie écran : 2

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

  y' = 1 + y/x,

 with n = 100 

                    y_n = 7.3862695068

 The exact value is y   = 7.38629

 Press return to continue.