01: #include <stdio.h>
02: #define NSTEPS 20
03: #define NDIM 30000
04: #define X_MAX 2.0
05:
06: double f(double x, double y);
07:
08:
09:
10:
11: int main(void){
12: double x[NDIM], y[NDIM];
13: double dx, error;
14: int i;
15: FILE *out;
16:
17:
18: dx = X_MAX/NSTEPS;
19: x[0] = 0;
20: y[0] = 0;
21:
22:
23:
24:
25: for(i=0; i<NSTEPS; i++){
26: x[i+1] = x[0]+(i+1)*dx;
27: y[i+1] = y[i]+f(x[i],y[i])*dx;
28: }
29:
30:
31:
32:
33: out = fopen("result.txt","w");
34: for(i=0; i<=NSTEPS; i++){
35: error = x[i]*x[i]-y[i];
36: fprintf(out,"%20.15f\t%20.15f\t%20.15f\n", x[i],y[i],error);
37: }
38:
39:
40: fclose(out);
41:
42: return 0;
43: }
44:
45:
46:
47:
48: double f(double x, double y){
49: return 2*x;
50: }