// PROGRAM example #include "TrueBASIC.h" int main(); void initial(double *y, double *x, double *delta_x, double *xmax); void Euler(double *y, double *x, double delta_x); int main() // beginning of main program { double delta_x, x, xmax, y; // specify initial values and parameters initial(&y, &x, &delta_x, &xmax); while(x <= xmax) { Euler(&y, &x, delta_x); // use simple Euler algorithm printf("%12f %12f\n", x, y); } return 0; } // end of main program void initial(double *y, double *x, double *delta_x, double *xmax) { (*x) = 1; // initial value of x (*y) = 1; // initial value of y (*xmax) = 2; // maximum value of x (*delta_x) = 0.1; // step size printf(" x y \n"); // print heading printf("\n"); // skip line printf("%12f %12f\n", (*x), (*y)); // print initial values } void Euler(double *y, double *x, double delta_x) { double change, slope; // variables slope and change introduced for sake of clarity only slope = 2*(*x); // slope at beginning of interval change = slope*delta_x; // estimate of change during interval (*y) += change; // new value of y (*x) += delta_x; // value of x at end of interval }