/* This is a handy utility to calculate cumulative errors in the * series generated by the numerical solutions programs for Homework 7 * ecalc.c V 0.9 written in C by Stefan Joe-Yen November 1995 */ #include<stdio.h> #include<stdlib.h> #include<math.h> /* Set Up the size of the standard and experimental series */ #define N 10 #define N2 5 main() { float t[N+1], w[N+1], t2[N2+1], w2[N2+1], error[N2+1], cerror; int i, j, stride; /* Initialize variables */ stride = N/N2; cerror = 0; /* Input the data */ for (i=0; i<=N; i++) { scanf("%f %f", &t[i], &w[i]); } for (i=0; i<=N2; i++) { scanf("%f %f", &t2[i], &w2[i]); } /* calculate the cumulative error */ for (i=0; i<=N2; i++) { error[i] = fabs(w[stride * i] - w2[i]); /* printf("%f %f %f\r\n", w[stride * i], w2[i], error[i]); /* diagnostic */ cerror += error[i]; } /* Print cumulative and average error */ printf("Cumulative error for the series is %f\r\n", cerror); printf("Average error for the series is %f\r\n", cerror/(N2+1)); }