Aller au contenu

Mathc initiation/Fichiers h : x 19c1a

Un livre de Wikilivres.

Sommaire

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

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

   n =       10.0;
   a =        1.0;
   b =        2.4;
  y0 =        1.59;

 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,
                        Yp);

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

 printf(" The exact value is y   = 5.790805\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,
                        Yp)
        );

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

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


Calculons la solution numérique de l'équation

y' = 1.0 + (y-x)**2  pour 1 < x <  2.4
avec comme condition initial y0 = 1.59 quand x = 1


Exemple de sortie écran 1 :

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

  y' = 1.0 + (y-x)**2

  k  | x_k   | y_k         
 --------------------------
   1 | 1.140 | +1.7787340000
   2 | 1.280 | +1.9758513572
   3 | 1.420 | +2.1836406328
   4 | 1.560 | +2.4052812150
   5 | 1.700 | +2.6453112616
   6 | 1.840 | +2.9104171349
   7 | 1.980 | +3.2108281329
   8 | 2.120 | +3.5629194379
   9 | 2.260 | +3.9944017485
  10 | 2.400 | +4.5555426680


                    y_n = 4.5555426680

 The exact value is y   = 5.790805

 Press return to continue.


Exemple de sortie écran : 2

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

  y' = 1.0 + (y-x)**2,

 with n = 10000000 

                    y_n = 5.7908017783

 The exact value is y   = 5.790805

 Press return to continue.