
/* Euler method. */

#include <stdio.h>
#include <math.h>

float dxdt(float x, float t)
{
    return x;
}

float true_solution(float x0, float t)

/* Modify this when dxdt is changed! */

{
    return x0 * exp(t);
}

void output(float x0, float x, float t)
{
    printf("%f %f %f\n", t, x, x - true_solution(x0, t));
}

main()
{
    /* Euler integrator x(t). */

    float x, x0, t, dt;

    /* Initial conditions: */

    t = 0;
    x = x0 = 1;

    dt = .1;

    while (t < 1) {

	float dx;

	output(x0, x, t);

	dx = dt*dxdt(x, t);
	t += dt;
	x += dx;
    }
    output(x0, x, t);
}
