Program

/* Euler  algorithm for first order differential equation */

#include <stdio.h>
 
#define dist 0.5		/* stepsize in t */
#define MAX 4.0			/* max for t */ 
 
FILE *output;			/* internal filename */

main()
{
double t, y;
int j;

output=fopen("euler.dat", "w");	/* external filename */

y=1;				/* initial condition */
fprintf(output, "0\t%f\n", y);

for (j=1;dist*j<=MAX;j++)	/* the time loop */
{
   t=j*dist;
   y-=dist*y;
 
   fprintf (output, "%f\t%f\n", t, y);
}

fclose(output);
}

A source code which you can save and run on your computer.
Back to main document.