// test simple polyfit.c only y = f(x) given x,y pairs #include "polyfit.h" #include "polyval.h" #include "simeq.h" #include #include #undef abs #define abs(x) ((x)<0.0?(-(x)):(x)) int main(int argc, char argv[]) { #define n 10 #define pwr 3 double x[n]; double y[n]; double yc[n]; // for checking double p[n+1]; double err; int i, j; printf("Testing polyval and polyfit.c \n"); printf("given x,y i=0 to n-1 y[i] = f(x[i]) \n"); printf("find p[] polynomial coefficients that fit f \n"); printf("y[i] = p[0] + p[1]*x[i] + p[2]*x[i]^2 + p[3]*x[i]^3 ... +p[pwr]*x[i]^pwr \n"); for(j=0; j<=pwr; j++) { p[j] = 1.2*(double)(j+1); // for computing y printf("j=%d p[j]=%f \n", j, p[j]); } for(i=0; i