XLL+ Class Library (7.0)

# Two-dimensional linear interpolation function

The function LinearInterp2D() implements linear interpolation on a two-dimensional surface.

LinearInterp2D()'s matrix argument aadZ is passed as an array of pointers to one-dimensional arrays of doubles. Each of these arrays of doubles represents one column of data. LinearInterp2D() returns 1 if it succeeds, 0 if it fails.

Add the code to the end of Tutorial1.cpp.

CopyC++
```static int FindInterpPoints(int cPoints, double* adValues, double dInterp, int* cc);

// Interpolate in a 2 dimensional array
// Returns 1 for success, 0 for failure
double dXInterp, double dYInterp, double* pdZInterp)
{
int ccX[2], ccY[2], i;

// Find the right poionts to use for interpolation
return 0;
return 0;

// Interpolate in the X dimension
for (i = 0; i < 2; i++) {
if (ccX[0] == ccX[1])
else
* ( dXInterp - adX[ccX[0]] )
}

// Interpolate in the Y dimension
if (ccY[0] == ccY[1])
else
* ( dYInterp - adY[ccY[0]] )
return 1;
}

// Locate the interpolation points in an ordered unique array
// Puts the coordinates of the two points in cc[]
// Returns 1 for success, 0 for failure
static int FindInterpPoints(int cPoints, double* adValues, double dInterp, int* cc)
{
int i;

// Too few points
if (cPoints < 1)
return 0;
// Only one point
if (cPoints == 1) {
cc[0] = cc[1] = 0;
return 1;
}
// Only two points
if (cPoints == 2) {
cc[0] = 0;
cc[1] = 1;
return 1;
}
// Find position of dInterp in adValues[]
for (i = 0; i < cPoints; i++) {
// Check that adValues[] is strongly ordered
return 0;
// Look for an exact match
cc[0] = cc[1] = i;
return 1;
}
// Find upper bound
// Extrapolate left
if (i == 0) {
cc[0] = 0;
cc[1] = 1;
}
// Interpolate
else {
cc[0] = i - 1;
cc[1] = i;
}
return 1;
}
}
// Extrapolate right
cc[0] = cPoints - 2;
cc[1] = cPoints - 1;
return 1;
}```