#include #include #include /* The following are parameters. They can be changed. h and eta are set as follows: h= hmult* 10^{ hpower} eta = etamult* 10^{etapower} */ #define kfinal 200 #define k0 2 #define hpower -8 #define hmult 2 #define etapower -15 #define etamult 5 /* The following are the variables for the numerical solution of the system of differential equations. They match the notation from the paper. X[i] = \tilde{x}_i(t) g[k] = g(k) = transition parameter for phase k Xp[i] = holds the next value of X[i] during the calculations k = current Phase */ double X[kfinal+1],Xp[kfinal+1],g[kfinal+1],t,h; int i,k; /* The following variables are used in bounding the errors. Again, they match the notation from the paper. E[i] = upper bound on the absolute value of e_i(t) = x_i(t) - \tilde{x}_i(t) Ep[i] = holds the next value of E[i] during the calculations f = upper bound on the absolute value of 1 - \sum_{i=1}^k i \tilde{x}_i(t) = 1 - \sum_{i=1}^k i X[i] maxe = maximum of E[i] over i =1, ..., k (this is diagnostic only. it is output but not used anywhere in the error bounds) eta = maximum error in a floating point operation */ double f, E[kfinal+1], Ep[kfinal+1], maxe, eta; /* These functions due the main calculations dxi returns F_i(\tilde{ \bf x}) dx0 returns F_0(\tilde{ \bf x}) errxi returns upper bound on the absolute value of e_i(t+h), following the methods discussed in the paper errx0 return an upper bound on the absolute value of e_0(t+h). */ double dxi(double *yy, long k, long i); double dx0(double *yy, long k); double errxi(double *ee, double *yy, long k, long i, double h, double eta, double f); double errx0(double *ee, double *yy, long k, double h, double eta, double f); int main(void) { /* Initialization of everything */ h = hmult*exp( log(10.0)* hpower); eta = etamult*exp( log(10.0)* etapower); k = k0; t = 0; f = 0; X[0]=0; X[1]=1; for (i=2;i<=kfinal;++i) X[i] = 0.0; for (i=0;i<=kfinal;++i) E[i] = 0.0; for (i=1;i= t*g[k]) && (X[0]-E[0] >= t*0.5) ) /* time loop */ { Xp[0] = X[0] + h*dx0(X,k); for(i=1; i<= k; ++i) Xp[i] = X[i] + h*dxi(X,k,i); Ep[0] = errx0(E,X,k,h,eta,f); for(i=1; i<= k; ++i) Ep[i] = errxi(E,X,k,i,h,eta,f); for(i=0; i<= k; ++i) { X[i] = Xp[i]; E[i] = Ep[i]; } /* Calculation of f for use in next step */ f=0; for(i=1; i<= k; ++i) f = f + i*X[i]; f = fabs( f - 1); f = f + 2*k*eta; t=t+h; } /* end of time loop */ /* Output of diagnostic information */ maxe=0; for(i=1; i <=k; ++i) if( E[i]>= maxe ) maxe=E[i]; printf("k=%i t=%8f ratio=%8f maxe=%le f= %le E[0]= %le " ,k, t, X[0]/t, maxe, f, E[0]); printf("\n"); k=k+1; } /* end of Phase loop */ } double dxi(double *yy, long k, long i) { long j,ell; double sum; sum=0; for(j=1;j