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