Mathc initiation/Fichiers h : x 19a3

Sommaire

Installer ce fichier dans votre répertoire de travail.

x_euler.h
utilitaire
/* ---------------------------------- */
/* save as x_euler.h                  */
/* ---------------------------------- */
double Euler_s_Method(
double a,
double b,
double n,
double ya,
double (*P_f)(double x,double y)
)
{
double i;
double h;
double x_k;

    h = ((b-a)/n);

    for(i=1,x_k=a; i<=n; i++)
        {
         ya = ya + h*(*P_f)(x_k,ya);
         x_k +=h;
        }

 return(ya);
}
/* --------------------------------- */
/* --------------------------------- */
void p_Euler_s_Method(
double a,
double b,
double n,
double ya,
double (*P_f)(double x,double y)
)
{
double i;
double h;
double x_k;

    h = ((b-a)/n);

    printf("  k  | x_k   | y_k         \n");
    printf(" --------------------------\n");
    for(i=1,x_k=a; i<=n; i++)
        {
         ya = ya + h*(*P_f)(x_k,ya);
         x_k +=h;
         printf(" %3.f | %.3f | %+.10f\n",i,x_k,ya);
        }
        
    printf("\n\n");   
}
/* --------------------------------- */
/* --------------------------------- */
Déclaration des fonctions de calcul.