/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void constFuncDiffTest() { DoubleMatrix coefsMatrix = DoubleMatrix.copyOf( new double[][] { {-1 }, {20 }, {0. }, {5 }, {1. }, {0. } }); double[] xKeys = new double[] {-2, 1, 2, 2.5 }; final int dim = 2; final int nCoefs = 1; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(X_VALUES, coefsMatrix, nCoefs, dim); PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); function.differentiate(pp, xKeys[0]); }
new PiecewisePolynomialResult(X_VALUES, DoubleMatrix.copyOf(coefMat), 5, 1); final DoubleArray differentiate = function.differentiate(result, xKeys).row(0); final DoubleArray differentiateTwice = function.differentiateTwice(result, xKeys).row(0); final double[][] integrate = new double[nInit][nKeys]; assertEquals(function.differentiate(result, xKeys[0]).get(0), differentiateExp[0], ref * EPS); assertEquals(function.differentiate(result, xKeys[3]).get(0), differentiateExp[3], ref * EPS);
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void constFuncDiffMultiTest() { DoubleMatrix coefsMatrix = DoubleMatrix.copyOf( new double[][] { {-1 }, {20 }, {0. }, {5 }, {1. }, {0. } }); double[] xKeys = new double[] {-2, 1, 2, 2.5 }; final int dim = 2; final int nCoefs = 1; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(X_VALUES, coefsMatrix, nCoefs, dim); PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); function.differentiate(pp, xKeys); }
final DoubleArray differentiate = function.differentiate(result, xKeys).row(0); final DoubleArray differentiateTwice = function.differentiateTwice(result, xKeys).row(0); final double[][] integrate = new double[nInit][nKeys];
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void nullxDiffTest() { DoubleMatrix coefsMatrix = DoubleMatrix.copyOf( new double[][] { {1., -3., 3., -1 }, {0., 5., -20., 20 }, {1., 0., 0., 0. }, {0., 5., -10., 5 }, {1., 3., 3., 1. }, {0., 5., 0., 0. } }); double[] xKeys = new double[] {-2, 1, 2, 2.5 }; final int dim = 2; final int nCoefs = 4; xKeys = null; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(X_VALUES, coefsMatrix, nCoefs, dim); PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); function.differentiate(pp, xKeys); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void nullpDifferentiateTest() { final DoubleMatrix coefsMatrix = DoubleMatrix.copyOf( new double[][] { {1., -3., 3., -1 }, {0., 5., -20., 20 }, {1., 0., 0., 0. }, {0., 5., -10., 5 }, {1., 3., 3., 1. }, {0., 5., 0., 0. } }); final double[][] xKeys = new double[][] { {-2, 1, 2, 2.5 }, {1.5, 7. / 3., 29. / 7., 5. } }; final int dim = 2; final int nCoefs = 4; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(X_VALUES, coefsMatrix, nCoefs, dim); pp = null; PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); function.differentiate(pp, xKeys[0][0]); }
/** * */ @Test(expectedExceptions = IllegalArgumentException.class) public void nullpDifferentiateMultiTest() { final DoubleMatrix coefsMatrix = DoubleMatrix.copyOf( new double[][] { {1., -3., 3., -1 }, {0., 5., -20., 20 }, {1., 0., 0., 0. }, {0., 5., -10., 5 }, {1., 3., 3., 1. }, {0., 5., 0., 0. } }); final double[][] xKeys = new double[][] { {-2, 1, 2, 2.5 }, {1.5, 7. / 3., 29. / 7., 5. } }; final int dim = 2; final int nCoefs = 4; PiecewisePolynomialResult pp = new PiecewisePolynomialResult(X_VALUES, coefsMatrix, nCoefs, dim); pp = null; PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); function.differentiate(pp, xKeys[0]); }
diff0 = func.differentiate(result0, x0Values).toArray(); diff1 = func.differentiate(result1, x1Values).toArray();
final DoubleArray differentiate = function.differentiate(result, xKeys).row(0); final double[][] integrate = new double[nInit][nKeys]; for (int i = 0; i < nInit; ++i) {
DoubleMatrix expDiffX0 = func1D.differentiate( method.interpolate(x0Values, OG_ALGEBRA.getTranspose(DoubleMatrix.copyOf(yValues)).toArray()), x0Values); DoubleMatrix expDiffX1 = func1D.differentiate(method.interpolate(x1Values, yValues), x1Values);
/** * Consistency with evaluate and differentiate. */ @Test public void evaluateAndDifferentiateTest() { double[][][] coefsMatrix = new double[][][] { { {1., -3., 3., -1 }, {1., 0., 0., 0. }, {1., 3., 3., 1. }, }, { {0., 5., -20., 20 }, {0., 5., -10., 5 }, {0., 5., 0., 0. } } }; double[][] xKeys = new double[][] { {-2, 1, 2, 2.5 }, {1.5, 7. / 3., 29. / 7., 5. } }; int dim = 2; int nCoefs = 4; int keyLength = xKeys[0].length; PiecewisePolynomialResult[] pp = new PiecewisePolynomialResult[dim]; for (int i = 0; i < dim; ++i) { pp[i] = new PiecewisePolynomialResult(X_VALUES, DoubleMatrix.ofUnsafe(coefsMatrix[i]), nCoefs, 1); } PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D(); for (int i = 0; i < dim; ++i) { for (int j = 0; j < keyLength; ++j) { ValueDerivatives computed = function.evaluateAndDifferentiate(pp[i], xKeys[i][j]); double value = function.evaluate(pp[i], xKeys[i][j]).get(0); double deriv = function.differentiate(pp[i], xKeys[i][j]).get(0); assertEquals(computed.getValue(), value, EPS); assertEquals(computed.getDerivatives().size(), 1); assertEquals(computed.getDerivative(0), deriv, EPS); } } }
DoubleMatrix expDiffX0 = func1D.differentiate(method.interpolate( x0Values, OG_ALGEBRA.getTranspose(DoubleMatrix.copyOf(yValues)).toArray()), x0Values); DoubleMatrix expDiffX1 = func1D.differentiate(method.interpolate(x1Values, yValues), x1Values);
DoubleMatrix expDiffX0 = func1D.differentiate(method.interpolate( x0Values, OG_ALGEBRA.getTranspose(DoubleMatrix.copyOf(yValues)).toArray()), x0Values); DoubleMatrix expDiffX1 = func1D.differentiate(method.interpolate(x1Values, yValues), x1Values);