/** Compute exponential of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * exponential the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void exp(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; Arrays.fill(function, FastMath.exp(operand[operandOffset])); // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Computes shifted logarithm of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * shifted logarithm the result array <em>cannot</em> be the input array) * @param resultOffset offset of the result in its array */ public void log1p(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.log1p(operand[operandOffset]); if (order > 0) { double inv = 1.0 / (1.0 + operand[operandOffset]); double xk = inv; for (int i = 1; i <= order; ++i) { function[i] = xk; xk *= -i * inv; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Compute natural logarithm of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * logarithm the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void log(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.log(operand[operandOffset]); if (order > 0) { double inv = 1.0 / operand[operandOffset]; double xk = inv; for (int i = 1; i <= order; ++i) { function[i] = xk; xk *= -i * inv; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Compute power of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param p power to apply * @param result array where result must be stored (for * power the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void pow(final double[] operand, final int operandOffset, final double p, final double[] result, final int resultOffset) { // create the function value and derivatives // [x^p, px^(p-1), p(p-1)x^(p-2), ... ] double[] function = new double[1 + order]; double xk = FastMath.pow(operand[operandOffset], p - order); for (int i = order; i > 0; --i) { function[i] = xk; xk *= operand[operandOffset]; } function[0] = xk; double coefficient = p; for (int i = 1; i <= order; ++i) { function[i] *= coefficient; coefficient *= p - i; } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Compute exp(x) - 1 of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * exponential the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void expm1(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.expm1(operand[operandOffset]); Arrays.fill(function, 1, 1 + order, FastMath.exp(operand[operandOffset])); // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
compose(operand, operandOffset, function, result, resultOffset);
compose(operand, operandOffset, function, result, resultOffset);
compose(operand, operandOffset, function, result, resultOffset);
compose(operand, operandOffset, function, result, resultOffset);
/** Compute sine of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * sine the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void sin(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.sin(operand[operandOffset]); if (order > 0) { function[1] = FastMath.cos(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = -function[i - 2]; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Compute hyperbolic cosine of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * hyperbolic cosine the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void cosh(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.cosh(operand[operandOffset]); if (order > 0) { function[1] = FastMath.sinh(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = function[i - 2]; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Compute cosine of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * cosine the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void cos(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.cos(operand[operandOffset]); if (order > 0) { function[1] = -FastMath.sin(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = -function[i - 2]; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Compute hyperbolic sine of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * hyperbolic sine the result array <em>cannot</em> be the input * array) * @param resultOffset offset of the result in its array */ public void sinh(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.sinh(operand[operandOffset]); if (order > 0) { function[1] = FastMath.cosh(operand[operandOffset]); for (int i = 2; i <= order; ++i) { function[i] = function[i - 2]; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
/** Computes base 10 logarithm of a derivative structure. * @param operand array holding the operand * @param operandOffset offset of the operand in its array * @param result array where result must be stored (for * base 10 logarithm the result array <em>cannot</em> be the input array) * @param resultOffset offset of the result in its array */ public void log10(final double[] operand, final int operandOffset, final double[] result, final int resultOffset) { // create the function value and derivatives double[] function = new double[1 + order]; function[0] = FastMath.log10(operand[operandOffset]); if (order > 0) { double inv = 1.0 / operand[operandOffset]; double xk = inv / FastMath.log(10.0); for (int i = 1; i <= order; ++i) { function[i] = xk; xk *= -i * inv; } } // apply function composition compose(operand, operandOffset, function, result, resultOffset); }
compose(operand, operandOffset, function, result, resultOffset);
compose(operand, operandOffset, function, result, resultOffset);
compose(operand, operandOffset, function, result, resultOffset);
/** Compute composition of the instance by a univariate function. * @param f array of value and derivatives of the function at * the current point (i.e. [f({@link #getValue()}), * f'({@link #getValue()}), f''({@link #getValue()})...]). * @return f(this) * @exception DimensionMismatchException if the number of derivatives * in the array is not equal to {@link #getOrder() order} + 1 */ public DerivativeStructure compose(final double ... f) throws DimensionMismatchException { if (f.length != getOrder() + 1) { throw new DimensionMismatchException(f.length, getOrder() + 1); } final DerivativeStructure result = new DerivativeStructure(compiler); compiler.compose(data, 0, f, result.data, 0); return result; }
compose(operand, operandOffset, function, result, resultOffset);
compose(operand, operandOffset, function, result, resultOffset);