/* test horner2d.c */ #include #include "horner2d.h" int main(int argc, char * argv[]) { double x=2.5; double y=3.3; double z, zc, err; double a0[1] = {66.0}; double a1[3] = {66.0, 65.0, 64.0}; double a2[6] = {66.0, 65.0, 64.0, 63.0, 62.0, 61.0}; double a3[10] = {66.0, 65.0, 64.0, 63.0, 62.0, 61.0, 60.0, 59.0, 58.0, 57.0}; printf("test_horner2d.c running \n"); printf("npowwer=0, nterm=1, x=%f, y=%f \n", x, y); z = horner2d(0, a0, x, y); zc = a0[0]; err = z - zc; printf("horner2d=%f, check=%f, err=%g \n\n", z, zc, err); printf("npowwer=1, nterm=3, x=%f, y=%f \n", x, y); z = horner2d(1, a1, x, y); zc = a1[0]+a1[1]*x+a1[2]*y; err = z - zc; printf("horner2d=%f, check=%f, err=%g \n\n", z, zc, err); printf("npowwer=2, nterm=6, x=%f, y=%f \n", x, y); z = horner2d(2, a2, x, y); zc = a2[0]+a2[1]*x+a2[2]*y+a2[3]*x*x+a2[4]*x*y+a2[5]*y*y; err = z - zc; printf("horner2d=%f, check=%f, err=%g \n\n", z, zc, err); printf("npowwer=3, nterm=10, x=%f, y=%f \n", x, y); z = horner2d(3, a3, x, y); zc = a3[0]+a3[1]*x+a3[2]*y+a3[3]*x*x+a3[4]*x*y+a3[5]*y*y+ a3[6]*x*x*x+a3[7]*x*x*y+a3[8]*x*y*y+a3[9]*y*y*y; err = z - zc; printf("horner2d=%f, check=%f, err=%g \n\n", z, zc, err); printf("test_horner2d.c finished \n"); return 0; }