PiecewisePolynomialFunction1D { public DoubleMatrix1D differentiateTwice(final PiecewisePolynomialResult pp, final double xKey) { ArgumentChecker.notNull(pp, "pp"); ArgumentChecker.isFalse(pp.getOrder() < 3, "polynomial degree < 2"); final double[][] coefs = pp.getCoefMatrix().getData(); final double[] knots = pp.getKnots().getData(); final int nKnots = pp.getNumberOfIntervals() + 1; final int nCoefs = pp.getOrder(); final int dim = pp.getDimensions(); double[][] res = new double[dim * (nKnots - 1)][nCoefs - 2]; for (int i = 0; i < dim * (nKnots - 1); ++i) { Arrays.fill(res[i], 0.); } for (int i = 0; i < dim * (nKnots - 1); ++i) { for (int j = 0; j < nCoefs - 2; ++j) { res[i][j] = coefs[i][j] * (nCoefs - j - 1) * (nCoefs - j - 2); } } PiecewisePolynomialResult ppDiff = new PiecewisePolynomialResult(new DoubleMatrix1D(knots), new DoubleMatrix2D(res), nCoefs - 1, pp.getDimensions()); return evaluate(ppDiff, xKey); } PiecewisePolynomialFunction1D(); DoubleMatrix1D evaluate(final PiecewisePolynomialResult pp, final double xKey); DoubleMatrix2D evaluate(final PiecewisePolynomialResult pp, final double[] xKeys); DoubleMatrix2D[] evaluate(final PiecewisePolynomialResult pp, final double[][] xKeys); DoubleMatrix1D differentiate(final PiecewisePolynomialResult pp, final double xKey); DoubleMatrix2D differentiate(final PiecewisePolynomialResult pp, final double[] xKeys); DoubleMatrix1D differentiateTwice(final PiecewisePolynomialResult pp, final double xKey); DoubleMatrix2D differentiateTwice(final PiecewisePolynomialResult pp, final double[] xKeys); double integrate(final PiecewisePolynomialResult pp, final double initialKey, final double xKey); DoubleMatrix1D integrate(final PiecewisePolynomialResult pp, final double initialKey, final double[] xKeys);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void linearFuncDiffTwiceTest() { double[] xValues = new double[] {1, 2, 3, 4 }; DoubleMatrix2D coefsMatrix = new DoubleMatrix2D( new double[][] { {1., -3. }, {0., 5. }, {1., 0. }, {0., 5. }, {1., 3. }, {0., 5. } }); double[] xKeys = new double[] {-2, 1, 2, 2.5 }; final int dim = 2; final int nCoefs = 2; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(new DoubleMatrix1D(xValues), coefsMatrix, nCoefs, dim); PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); function.differentiateTwice(pp, xKeys[0]); }
@Test(expectedExceptions = IllegalArgumentException.class) public void linearFuncDiffTwiceMultiTest() { double[] xValues = new double[] {1, 2, 3, 4 }; DoubleMatrix2D coefsMatrix = new DoubleMatrix2D( new double[][] { {1., -3. }, {0., 5. }, {1., 0. }, {0., 5. }, {1., 3. }, {0., 5. } }); double[] xKeys = new double[] {-2, 1, 2, 2.5 }; final int dim = 2; final int nCoefs = 2; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(new DoubleMatrix1D(xValues), coefsMatrix, nCoefs, dim); PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); function.differentiateTwice(pp, xKeys); }