// name: Devin Scott N23 CS407 // Assignment A02 #include #include int signof(double x) //return 1 if the sign is positive , 0 if it is negative { if (x >= 0) return 1; else return 0; } double interpolate(int numberofpairs, double xvalues[], double yvalues[], double bigx, int k) { double result = 40.2; int i =0; int j =0; int nexthigher=0; int kbegin=0; int kend=0; int aflag =0; double product; double summation; int r=0; double temproduct=0; double temproduct2=0; double temproduct3=0; double temproduct4=0; j=numberofpairs; for (i = 1; i <= j; i++) { printf("\n x%d : %lf , y%d : %lf \n", i,xvalues[i],i,yvalues[i]); } if (bigx >xvalues[1] && bigx < xvalues[j]) //normal middle case { //interpolation points will be half k points after and the remainder points before the point that is found just higher than bigx. if (bigx > xvalues[j-1]) //if target bigx is greater than the second to last point { //interpolation points will be j, j-1, j-2 .. j-k printf("target is close to the last point\n"); aflag=1; } if (bigx < xvalues[2]) //if target bigx is smaller than the second point. { //interpolation points will be 1, 2, 3 .. k printf("target is close to the first point\n"); aflag=1; } for (i=1; i <= j; i++) //find xi that is just higher than bigx { if (xvalues[i] > bigx) { nexthigher = i; printf("the point that is just bigger than bigx %lf is %lf \n",bigx, xvalues[nexthigher]); break; } } if (aflag == 0) { //identify the range of k as nexthigher + (k/2 -1) points ahead and - k/2 points behind kbegin = nexthigher - ( k - (k/2) ); kend = nexthigher + (k/2) -1; if (kbegin < 1) //adjustment needs to be made if overflow occurs { kend = kend + abs(kbegin) + 1; //move nodes from beginning range of k to end range kbegin = kbegin + abs(kbegin) +1; } if (kend > j) //k was too big! { kend = kend - (k-j); //move nodes from end range of k to begin range kbegin = kbegin - (k-j); } if (kbegin < 1 || kend > j) { printf("unhandled overflow occured k was too big\n"); } printf("the range of k has been identified as: %d to %d \n",kbegin,kend); } } product = 1; summation =0; for (i =1; i