Java Code Examples for org.apache.commons.math3.util.FastMath#cbrt()

The following examples show how to use org.apache.commons.math3.util.FastMath#cbrt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DSCompiler.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Compute n<sup>th</sup> root of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param n order of the root
 * @param result array where result must be stored (for
 * n<sup>th</sup> root the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void rootN(final double[] operand, final int operandOffset, final int n,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]
    double[] function = new double[1 + order];
    double xk;
    if (n == 2) {
        xk = FastMath.sqrt(operand[operandOffset]);
    } else if (n == 3) {
        xk = FastMath.cbrt(operand[operandOffset]);
    } else {
        xk = FastMath.pow(operand[operandOffset], 1.0 / n);
    }
    final double nReciprocal = 1.0 / n;
    final double xReciprocal = 1.0 / operand[operandOffset];
    for (int i = 0; i <= order; ++i) {
        function[i] = xk;
        xk *= xReciprocal * (nReciprocal - i);
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 2
Source File: DSCompiler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Compute n<sup>th</sup> root of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param n order of the root
 * @param result array where result must be stored (for
 * n<sup>th</sup> root the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void rootN(final double[] operand, final int operandOffset, final int n,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]
    double[] function = new double[1 + order];
    double xk;
    if (n == 2) {
        function[0] = FastMath.sqrt(operand[operandOffset]);
        xk          = 0.5 / function[0];
    } else if (n == 3) {
        function[0] = FastMath.cbrt(operand[operandOffset]);
        xk          = 1.0 / (3.0 * function[0] * function[0]);
    } else {
        function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
        xk          = 1.0 / (n * FastMath.pow(function[0], n - 1));
    }
    final double nReciprocal = 1.0 / n;
    final double xReciprocal = 1.0 / operand[operandOffset];
    for (int i = 1; i <= order; ++i) {
        function[i] = xk;
        xk *= xReciprocal * (nReciprocal - i);
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 3
Source File: DSCompiler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Compute n<sup>th</sup> root of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param n order of the root
 * @param result array where result must be stored (for
 * n<sup>th</sup> root the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void rootN(final double[] operand, final int operandOffset, final int n,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]
    double[] function = new double[1 + order];
    double xk;
    if (n == 2) {
        function[0] = FastMath.sqrt(operand[operandOffset]);
        xk          = 0.5 / function[0];
    } else if (n == 3) {
        function[0] = FastMath.cbrt(operand[operandOffset]);
        xk          = 1.0 / (3.0 * function[0] * function[0]);
    } else {
        function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
        xk          = 1.0 / (n * FastMath.pow(function[0], n - 1));
    }
    final double nReciprocal = 1.0 / n;
    final double xReciprocal = 1.0 / operand[operandOffset];
    for (int i = 1; i <= order; ++i) {
        function[i] = xk;
        xk *= xReciprocal * (nReciprocal - i);
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 4
Source File: DSCompiler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Compute n<sup>th</sup> root of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param n order of the root
 * @param result array where result must be stored (for
 * n<sup>th</sup> root the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void rootN(final double[] operand, final int operandOffset, final int n,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]
    double[] function = new double[1 + order];
    double xk;
    if (n == 2) {
        function[0] = FastMath.sqrt(operand[operandOffset]);
        xk          = 0.5 / function[0];
    } else if (n == 3) {
        function[0] = FastMath.cbrt(operand[operandOffset]);
        xk          = 1.0 / (3.0 * function[0] * function[0]);
    } else {
        function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
        xk          = 1.0 / (n * FastMath.pow(function[0], n - 1));
    }
    final double nReciprocal = 1.0 / n;
    final double xReciprocal = 1.0 / operand[operandOffset];
    for (int i = 1; i <= order; ++i) {
        function[i] = xk;
        xk *= xReciprocal * (nReciprocal - i);
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 5
Source File: DSCompiler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Compute n<sup>th</sup> root of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param n order of the root
 * @param result array where result must be stored (for
 * n<sup>th</sup> root the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void rootN(final double[] operand, final int operandOffset, final int n,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]
    double[] function = new double[1 + order];
    double xk;
    if (n == 2) {
        function[0] = FastMath.sqrt(operand[operandOffset]);
        xk          = 0.5 / function[0];
    } else if (n == 3) {
        function[0] = FastMath.cbrt(operand[operandOffset]);
        xk          = 1.0 / (3.0 * function[0] * function[0]);
    } else {
        function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
        xk          = 1.0 / (n * FastMath.pow(function[0], n - 1));
    }
    final double nReciprocal = 1.0 / n;
    final double xReciprocal = 1.0 / operand[operandOffset];
    for (int i = 1; i <= order; ++i) {
        function[i] = xk;
        xk *= xReciprocal * (nReciprocal - i);
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 6
Source File: Cbrt.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateFunction derivative() {
    return new UnivariateFunction() {
        /** {@inheritDoc} */
        public double value(double x) {
            return 1 / (3 * FastMath.cbrt(x * x));
        }
    };
}
 
Example 7
Source File: Math_10_DSCompiler_t.java    From coming with MIT License 5 votes vote down vote up
/** Compute n<sup>th</sup> root of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param n order of the root
 * @param result array where result must be stored (for
 * n<sup>th</sup> root the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void rootN(final double[] operand, final int operandOffset, final int n,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]
    double[] function = new double[1 + order];
    double xk;
    if (n == 2) {
        function[0] = FastMath.sqrt(operand[operandOffset]);
        xk          = 0.5 / function[0];
    } else if (n == 3) {
        function[0] = FastMath.cbrt(operand[operandOffset]);
        xk          = 1.0 / (3.0 * function[0] * function[0]);
    } else {
        function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
        xk          = 1.0 / (n * FastMath.pow(function[0], n - 1));
    }
    final double nReciprocal = 1.0 / n;
    final double xReciprocal = 1.0 / operand[operandOffset];
    for (int i = 1; i <= order; ++i) {
        function[i] = xk;
        xk *= xReciprocal * (nReciprocal - i);
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 8
Source File: Cbrt.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public UnivariateFunction derivative() {
    return new UnivariateFunction() {
        /** {@inheritDoc} */
        public double value(double x) {
            return 1 / (3 * FastMath.cbrt(x * x));
        }
    };
}
 
Example 9
Source File: DSCompiler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Compute n<sup>th</sup> root of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param n order of the root
 * @param result array where result must be stored (for
 * n<sup>th</sup> root the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void rootN(final double[] operand, final int operandOffset, final int n,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]
    double[] function = new double[1 + order];
    double xk;
    if (n == 2) {
        function[0] = FastMath.sqrt(operand[operandOffset]);
        xk          = 0.5 / function[0];
    } else if (n == 3) {
        function[0] = FastMath.cbrt(operand[operandOffset]);
        xk          = 1.0 / (3.0 * function[0] * function[0]);
    } else {
        function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
        xk          = 1.0 / (n * FastMath.pow(function[0], n - 1));
    }
    final double nReciprocal = 1.0 / n;
    final double xReciprocal = 1.0 / operand[operandOffset];
    for (int i = 1; i <= order; ++i) {
        function[i] = xk;
        xk *= xReciprocal * (nReciprocal - i);
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 10
Source File: Math_10_DSCompiler_s.java    From coming with MIT License 5 votes vote down vote up
/** Compute n<sup>th</sup> root of a derivative structure.
 * @param operand array holding the operand
 * @param operandOffset offset of the operand in its array
 * @param n order of the root
 * @param result array where result must be stored (for
 * n<sup>th</sup> root the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 */
public void rootN(final double[] operand, final int operandOffset, final int n,
                  final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [x^(1/n), (1/n)x^((1/n)-1), (1-n)/n^2x^((1/n)-2), ... ]
    double[] function = new double[1 + order];
    double xk;
    if (n == 2) {
        function[0] = FastMath.sqrt(operand[operandOffset]);
        xk          = 0.5 / function[0];
    } else if (n == 3) {
        function[0] = FastMath.cbrt(operand[operandOffset]);
        xk          = 1.0 / (3.0 * function[0] * function[0]);
    } else {
        function[0] = FastMath.pow(operand[operandOffset], 1.0 / n);
        xk          = 1.0 / (n * FastMath.pow(function[0], n - 1));
    }
    final double nReciprocal = 1.0 / n;
    final double xReciprocal = 1.0 / operand[operandOffset];
    for (int i = 1; i <= order; ++i) {
        function[i] = xk;
        xk *= xReciprocal * (nReciprocal - i);
    }

    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
Example 11
Source File: Cbrt.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.cbrt(x);
}
 
Example 12
Source File: Cbrt.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.cbrt(x);
}
 
Example 13
Source File: Cbrt.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.cbrt(x);
}
 
Example 14
Source File: Cbrt.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.cbrt(x);
}
 
Example 15
Source File: Cbrt.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.cbrt(x);
}
 
Example 16
Source File: Cbrt.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.cbrt(x);
}
 
Example 17
Source File: Cbrt.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.cbrt(x);
}
 
Example 18
Source File: Cbrt.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.cbrt(x);
}