Example usage for java.lang Math cbrt

List of usage examples for java.lang Math cbrt

Introduction

In this page you can find the example usage for java.lang Math cbrt.

Prototype

public static double cbrt(double a) 

Source Link

Document

Returns the cube root of a double value.

Usage

From source file:Main.java

public static void main(String[] args) {

    double x = 125;
    double y = 10;

    // print the cube roots of three numbers
    System.out.println("Math.cbrt(" + x + ")=" + Math.cbrt(x));
    System.out.println("Math.cbrt(" + y + ")=" + Math.cbrt(y));
    System.out.println("Math.cbrt(-27)=" + Math.cbrt(-27));

}

From source file:Main.java

public static void main(String[] args) {
    int a = 10;/*  ww  w  .java2s  .co m*/
    int b = -50;
    int c = 3;
    double x = 25.0;
    double y = 3.0;
    double z = 4.0;

    System.out.println("abs(b)     = " + Math.abs(b));
    System.out.println("cbrt(x)   = " + Math.cbrt(x));
    System.out.println("exp(y)     = " + Math.exp(z));
    System.out.println("hypot(y, z)= " + Math.hypot(y, z));

    System.out.println("log(y)    = " + Math.log(y));
    System.out.println("log10(y)  = " + Math.log10(y));
    System.out.println("max(a, b) = " + Math.max(a, b));
    System.out.println("min(a, b) = " + Math.min(a, b));
    System.out.println("pow(a, c) = " + Math.pow(a, c));
    System.out.println("random()  = " + Math.random());
    System.out.println("signum(b) = " + Math.signum(b));
    System.out.println("sqrt(x)   = " + Math.sqrt(y));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    double data[] = { 12.3, 45.6, -7.89, -1.0, 1.01 };
    Formatter fmt = new Formatter();

    fmt.format("%12s %12s\n", "Value", "Cube Root");

    for (double v : data) {
        fmt.format("%12.4f %12.4f\n", v, Math.cbrt(v));
    }//from  ww w. java  2  s  .  com
    System.out.println(fmt);
}

From source file:com.caseystella.analytics.outlier.batch.rpca.AugmentedDickeyFuller.java

/**
 * Uses the Augmented Dickey Fuller test to determine
 * if ts is a stationary time series//from www  .  j a  v a2  s  . c  o m
 * @param ts
 */
public AugmentedDickeyFuller(double[] ts) {
    this.ts = ts;
    this.lag = (int) Math.floor(Math.cbrt((ts.length - 1)));
    computeADFStatistics();
}

From source file:com.opengamma.analytics.math.rootfinding.CubicRootFinder.java

/**
 * {@inheritDoc}//from w  ww.  jav  a2 s.  co  m
 * @throws IllegalArgumentException If the function is not cubic
 */
@Override
public ComplexNumber[] getRoots(final RealPolynomialFunction1D function) {
    Validate.notNull(function, "function");
    final double[] coefficients = function.getCoefficients();
    Validate.isTrue(coefficients.length == 4, "Function is not a cubic");
    final double divisor = coefficients[3];
    final double a = coefficients[2] / divisor;
    final double b = coefficients[1] / divisor;
    final double c = coefficients[0] / divisor;
    final double aSq = a * a;
    final double q = (aSq - 3 * b) / 9;
    final double r = (2 * a * aSq - 9 * a * b + 27 * c) / 54;
    final double rSq = r * r;
    final double qCb = q * q * q;
    final double constant = a / 3;
    if (rSq < qCb) {
        final double mult = -2 * Math.sqrt(q);
        final double theta = Math.acos(r / Math.sqrt(qCb));
        return new ComplexNumber[] { new ComplexNumber(mult * Math.cos(theta / 3) - constant, 0),
                new ComplexNumber(mult * Math.cos((theta + TWO_PI) / 3) - constant, 0),
                new ComplexNumber(mult * Math.cos((theta - TWO_PI) / 3) - constant, 0) };
    }
    final double s = -Math.signum(r) * Math.cbrt(Math.abs(r) + Math.sqrt(rSq - qCb));
    final double t = CompareUtils.closeEquals(s, 0, 1e-16) ? 0 : q / s;
    final double sum = s + t;
    final double real = -0.5 * sum - constant;
    final double imaginary = Math.sqrt(3) * (s - t) / 2;
    return new ComplexNumber[] { new ComplexNumber(sum - constant, 0), new ComplexNumber(real, imaginary),
            new ComplexNumber(real, -imaginary) };
}

From source file:com.opengamma.analytics.financial.var.JohnsonSUDeltaGammaVaRCalculator.java

private double getW0(final double t) {
    final double q = -2 - t * t;
    final double u = Math.cbrt(-q / 2. + Math.sqrt(q * q / 4. - 1));
    return -1. / u + u - 1;
}

From source file:com.opengamma.analytics.financial.var.JohnsonSUDeltaGammaVaRCalculator.java

private double getW1(final double k) {
    final double k2 = 2 * k;
    final double e = 2 * Math.sqrt((3 + k) * (16 * k * k + 87 * k + 171) / 27.);
    final double d = Math.cbrt(7 + k2 + e) - Math.cbrt(e - 7 - k2) - 1;
    final double sqrtD = Math.sqrt(d);
    return (sqrtD + Math.sqrt(4. / sqrtD - d - 3) - 1) / 2.;
}

From source file:org.apache.drill.exec.fn.impl.TestNewMathFunctions.java

@Test
public void testExtendedMathFunc() throws Throwable {
    final BigDecimal d = new BigDecimal(
            "100111111111111111111111111111111111.00000000000000000000000000000000000000000000000000001");
    final Object[] expected = new Object[] { Math.cbrt(1000), Math.log(10), Math.log10(5),
            (Math.log(64.0) / Math.log(2.0)), Math.exp(10), Math.toDegrees(0.5), Math.toRadians(45.0), Math.PI,
            Math.cbrt(d.doubleValue()), Math.log(d.doubleValue()), (Math.log(d.doubleValue()) / Math.log(2)),
            Math.exp(d.doubleValue()), Math.toDegrees(d.doubleValue()), Math.toRadians(d.doubleValue()) };
    runTest(expected, "functions/testExtendedMathFunctions.json");
}

From source file:tech.tablesaw.columns.numbers.NumberMapFunctions.java

default DoubleColumn cubeRoot() {
    DoubleColumn newColumn = DoubleColumn.create(name() + "[cbrt]", size());
    for (int i = 0; i < size(); i++) {
        newColumn.set(i, Math.cbrt(getDouble(i)));
    }/*from  w  w  w . j ava 2 s  .  co  m*/
    return newColumn;
}

From source file:com.facebook.presto.operator.scalar.MathFunctions.java

@Description("cube root")
@ScalarFunction/* w w w  .j a  v  a 2 s.c  o  m*/
@SqlType(StandardTypes.DOUBLE)
public static double cbrt(@SqlType(StandardTypes.DOUBLE) double num) {
    return Math.cbrt(num);
}