Aller au contenu

Mathc initiation/Fichiers h : x 21c1c

Un livre de Wikilivres.

Sommaire

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

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

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

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

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

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

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

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

 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 :

 Runge Kutta's method to approximate the solution
 of the differential equation.

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

  k  | x_k   | y_k         
 --------------------------
   1 | 0.200 | -1.3653
   2 | 0.400 | -1.2605
   3 | 0.600 | -1.1825
   4 | 0.800 | -1.1261
   5 | 1.000 | -1.0864
   6 | 1.200 | -1.0587
   7 | 1.400 | -1.0398
   8 | 1.600 | -1.0268
   9 | 1.800 | -1.0181
  10 | 2.000 | -1.0121
                    y_n = -1.0121464689

 The exact value is y   = -1.012136331

 Press return to continue.


Exemple de sortie écran : 2

  
 Runge Kutta's method to approximate the solution
 of the differential equation

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

 with n = 100 

                    y_n = -1.0121363318

 The exact value is y   = -1.012136331

 Press return to continue.