code: public double linearInterpolateY( double xValue ) {
  
          double first = xList[0];
          double last = xList[xList.length - 1];
  
          // check out of range
          if (first <= last) {
              if (xValue < xList[0] || xValue > xList[xList.length - 1]) {
                  return Double.NaN;
              }
              isInverse = false;
          } else {
              // inverse proportional
              if (xValue > xList[0] || xValue < xList[xList.length - 1]) {
                  return Double.NaN;
              }
              isInverse = true;
          }
  
          for( int i = 0; i < xList.length; i++ ) {
              double x2 = xList[i];
              // if equal to a number in the array
              if (NumericsUtilities.dEq(x2, xValue)) {
                  return yList[i];
              }// else interpolate
              else if ((!isInverse && x2 > xValue) || (isInverse && x2 < xValue)) {
                  double x1 = xList[i - 1];
                  double y1 = yList[i - 1];
                  double y2 = yList[i];
  
                  double y = (y2 - y1) * (xValue - x1) / (x2 - x1) + y1;
                  return y;
              }
          }
          return Double.NaN;
      }
docs: A simple interpolation between existing numbers.
  
  @param xValue the value for which we want the y
  @return the y value