@Test public void testValues() { double[] x = new double[] { 1, 3, 5, 7 }; double[] y = new double[] { 0, 10, 10, 5 }; LinearInterpolatedFunction fct = new LinearInterpolatedFunction(x, y); assertThat(fct.value(0), equalTo(y[0])); assertThat(fct.value(100), equalTo(y[y.length - 1])); for (int i = 0; i < x.length; i++) { assertThat(fct.value(x[i]), equalTo(y[i])); } assertThat(fct.value(5.5), equalTo(8.75)); }
public double value(double x0) { if (splineFunction != null && splineFunction.isValidPoint(x0)) { return splineFunction.value(x0); } if (x0 <= start.getX()) { return start.getY(); } if (x0 >= end.getX()) { return end.getY(); } throw new IllegalStateException("should not reach undefined function range=" + x0); }
LinearInterpolatedFunction { public double value(double x0) { if (splineFunction != null && splineFunction.isValidPoint(x0)) { return splineFunction.value(x0); } if (x0 <= start.getX()) { return start.getY(); } if (x0 >= end.getX()) { return end.getY(); } throw new IllegalStateException("should not reach undefined function range=" + x0); } }
LinearInterpolatedFunction { public double value(double x0) { if (splineFunction != null && splineFunction.isValidPoint(x0)) { return splineFunction.value(x0); } if (x0 <= start.getX()) { return start.getY(); } if (x0 >= end.getX()) { return end.getY(); } throw new IllegalStateException("should not reach undefined function range=" + x0); } LinearInterpolatedFunction(double[] x, double[] y); }
LinearInterpolatedFunction { public double value(double x0) { if (splineFunction != null && splineFunction.isValidPoint(x0)) { return splineFunction.value(x0); } if (x0 <= start.getX()) { return start.getY(); } if (x0 >= end.getX()) { return end.getY(); } throw new IllegalStateException("should not reach undefined function range=" + x0); } LinearInterpolatedFunction(double[] x, double[] y); int getNumberOfDataPoints(); double value(double x0); }
LinearInterpolatedFunction { public double value(double x0) { if (splineFunction != null && splineFunction.isValidPoint(x0)) { return splineFunction.value(x0); } if (x0 <= start.getX()) { return start.getY(); } if (x0 >= end.getX()) { return end.getY(); } throw new IllegalStateException("should not reach undefined function range=" + x0); } LinearInterpolatedFunction(double[] x, double[] y); int getNumberOfDataPoints(); double value(double x0);  }