Example usage for java.lang Math pow

List of usage examples for java.lang Math pow

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double pow(double a, double b) 

Source Link

Document

Returns the value of the first argument raised to the power of the second argument.

Usage

From source file:com.opengamma.analytics.financial.interestrate.PeriodicInterestRate.java

@Override
public double getDiscountFactor(final double t) {
    return Math.pow(_oneYearValue, -t);
}

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.NCauer.java

public NCauer(double Rp, double Rs, int n) {

    // Cutoff frequency = 1:
    double wp = 1;

    // Stop band edge ws:
    double ws = __ellip_ws(n, Rp, Rs);

    double k = wp / ws;
    double k1 = Math.sqrt(1.0 - Math.pow(k, 2));
    double q0 = (1.0 / 2.0) * ((1.0 - Math.sqrt(k1)) / (1 + Math.sqrt(k1)));
    double q = q0 + 2.0 * Math.pow(q0, 5) + 15.0 * Math.pow(q0, 9) + 150.0 * Math.pow(q0, 13); //%(....)
    double D = (Math.pow(10, 0.1 * Rs) - 1.0) / (Math.pow(10, (0.1 * Rp)) - 1.0);

    //Filter order maybe this, but not used now:
    //n=ceil(log10(16*D)/log10(1/q))

    double l = (1.0 / (2.0 * n)) * Math.log((Math.pow(10, 0.05 * Rp) + 1.0) / (Math.pow(10, 0.05 * Rp) - 1.0));
    double sig01 = 0;
    double sig02 = 0;
    for (int m = 0; m <= 30; m++) {
        sig01 = sig01 + Math.pow((-1), m) * Math.pow(q, (m * (m + 1))) * Math.sinh((2 * m + 1) * l);
    }/*w w w  .j av  a  2s . c  o  m*/
    for (int m = 1; m <= 30; m++) {
        sig02 = sig02 + Math.pow(-1.0, m) * Math.pow(q, (Math.pow(m, 2))) * Math.cosh(2 * m * l);
    }
    double sig0 = Math.abs((2.0 * Math.pow(q, (1.0 / 4.0)) * sig01) / (1.0 + 2.0 * sig02));

    double w = Math.sqrt((1.0 + k * Math.pow(sig0, 2)) * (1.0 + Math.pow(sig0, 2) / k));

    int r;
    if (n % 2 != 0) {
        r = (n - 1) / 2;
    } else {
        r = n / 2;
    }

    double[] wi = new double[r];
    for (int ii = 1; ii <= r; ii++) {
        double mu;
        if (n % 2 != 0) {
            mu = ii;
        } else {
            mu = (double) ii - 0.5;
        }
        double soma1 = 0;
        for (int m = 0; m <= 30; m++) {
            soma1 = soma1 + 2.0 * Math.pow(q, (1.0 / 4.0)) * (Math.pow(-1.0, m) * Math.pow(q, (m * (m + 1)))
                    * Math.sin(((2.0 * m + 1.0) * Math.PI * mu) / n));
        }
        double soma2 = 0;
        for (int m = 1; m <= 30; m++) {
            soma2 = soma2 + 2.0 * (Math.pow(-1.0, m) * Math.pow(q, (Math.pow(m, 2)))
                    * Math.cos((2.0 * m * Math.PI * mu) / n));
        }
        wi[ii - 1] = (soma1 / (1.0 + soma2));
    }

    double[] Vi = new double[wi.length];
    for (int i = 0; i < wi.length; i++) {
        Vi[i] = Math.sqrt((1.0 - (k * (Math.pow(wi[i], 2)))) * (1.0 - (Math.pow(wi[i], 2)) / k));
    }
    double[] A0i = new double[wi.length];
    for (int i = 0; i < wi.length; i++) {
        A0i[i] = 1.0 / (Math.pow(wi[i], 2));
    }
    double[] sqrA0i = new double[wi.length];
    for (int i = 0; i < wi.length; i++) {
        sqrA0i[i] = 1.0 / wi[i];
    }

    double[] B0i = new double[wi.length];
    for (int i = 0; i < wi.length; i++) {
        B0i[i] = (Math.pow((sig0 * Vi[i]), 2) + Math.pow((w * wi[i]), 2))
                / Math.pow((1.0 + Math.pow(sig0, 2) * Math.pow(wi[i], 2)), 2);
    }

    double C01;
    if (wi.length == 0) {
        C01 = 1.0;
    } else {
        C01 = B0i[0] / A0i[0];
        for (int i = 1; i < wi.length; i++) {
            C01 *= B0i[i] / A0i[i];
        }
    }

    //Gain T0:
    if (n % 2 != 0) {
        T0 = sig0 * C01 * Math.sqrt(ws);
    } else {
        T0 = Math.pow(10, (-0.05 * Rp)) * C01;
    }

    //zeros:
    zer = new Complex[sqrA0i.length * 2];
    for (int i = 0; i < sqrA0i.length; i++) {
        zer[i] = Complex.valueOf(0.0, sqrA0i[i]);
        zer[i + sqrA0i.length] = Complex.valueOf(0.0, -sqrA0i[i]);
    }

    //poles:
    pol = new Complex[Vi.length * 2];
    for (int i = 0; i < Vi.length; i++) {
        pol[i] = new Complex(-2.0 * sig0 * Vi[i], 2.0 * wi[i] * w)
                .divide(2.0 * (1 + Math.pow(sig0, 2) * Math.pow(wi[i], 2)));
        pol[i + Vi.length] = new Complex(-2.0 * sig0 * Vi[i], -2.0 * wi[i] * w)
                .divide(2.0 * (1 + Math.pow(sig0, 2) * Math.pow(wi[i], 2)));
    }

    //If n odd, there is a real pole  -sig0:
    if (n % 2 != 0) {
        pol = Arrays.copyOf(pol, pol.length + 1);
        pol[pol.length - 1] = new Complex(-sig0);
    }

    for (int i = 0; i < pol.length; i++) {
        pol[i] = pol[i].multiply(Math.sqrt(ws));
    }
    for (int i = 0; i < zer.length; i++) {
        zer[i] = zer[i].multiply(Math.sqrt(ws));
    }

}

From source file:math2605.MatrixMethods.java

public double determinant(double A[][], int N) {
    double det = 0;
    if (N == 1) {
        det = A[0][0];//from  w  w  w.  ja v  a2  s  . c o  m
    } else if (N == 2) {
        det = A[0][0] * A[1][1] - A[1][0] * A[0][1];
    } else {
        det = 0;
        for (int j1 = 0; j1 < N; j1++) {
            double[][] m = new double[N - 1][];
            for (int k = 0; k < (N - 1); k++) {
                m[k] = new double[N - 1];
            }
            for (int i = 1; i < N; i++) {
                int j2 = 0;
                for (int j = 0; j < N; j++) {
                    if (j == j1)
                        continue;
                    m[i - 1][j2] = A[i][j];
                    j2++;
                }
            }
            det += Math.pow(-1.0, 1.0 + j1 + 1.0) * A[0][j1] * determinant(m, N - 1);
        }
    }
    return det;
}

From source file:br.prof.salesfilho.oci.util.OCIUtils.java

public static double[] fft_magnitude(double[] input) {
    FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] complexTransInput = fft.transform(input, TransformType.FORWARD);
    for (int i = 0; i < complexTransInput.length; i++) {
        double real = (complexTransInput[i].getReal());
        double img = (complexTransInput[i].getImaginary());
        input[i] = (Math.pow(real, 2) + Math.pow(img, 2));
    }//w  w w  .java  2  s .co  m
    return input;
}

From source file:com.opengamma.analytics.financial.model.interestrate.HullWhiteOneFactorInterestRateModel.java

@Override
public Function1D<HullWhiteOneFactorDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time,
        final ZonedDateTime maturity) {
    Validate.notNull(time);/* w  ww  . j a  v  a  2s .c  o m*/
    Validate.notNull(maturity);
    return new Function1D<HullWhiteOneFactorDataBundle, Double>() {

        @Override
        public Double evaluate(final HullWhiteOneFactorDataBundle data) {
            Validate.notNull(data);
            final double t = DateUtils.getDifferenceInYears(data.getDate(), time);
            final double s = DateUtils.getDifferenceInYears(data.getDate(), maturity);
            final double rT = data.getShortRate(t);
            final double rs = data.getShortRate(s);
            final double pT = Math.exp(-rT * t);
            final double ps = Math.exp(-rs * s);
            final Double sigma = data.getShortRateVolatility(t);
            final double dt = s - t;
            final double speed = data.getReversionSpeed();
            final double b = (1 - Math.exp(-speed * dt)) / speed;
            final double upT = t + _delta;
            final double downT = t - _delta;
            final double dlnPdt = (-data.getShortRate(upT) * upT + data.getShortRate(downT) * downT)
                    / (2 * _delta);
            final double lnA = Math.log(ps / pT) - b * dlnPdt
                    - sigma * sigma * Math.pow(Math.exp(-speed * s) - Math.exp(-speed * t), 2)
                            * (Math.exp(2 * speed * t) - 1) / (4 * speed * speed * speed);
            return Math.exp(lnA - b * rT);
        }

    };
}

From source file:Main.java

private static double pivotXyzComponent(double component) {
    return component > XYZ_EPSILON ? Math.pow(component, 1 / 3.0) : (XYZ_KAPPA * component + 16) / 116;
}

From source file:com.clustercontrol.repository.util.NodeSearchUtil.java

/**
 * Generate default IP for node search/create dialog
 */// w  ww . ja v a 2  s .c  om
public static String generateDefaultIp(String def, int hostAddress) {
    try {
        // Get IP
        InetAddress addr = Inet4Address.getLocalHost();

        // Get subnet mask length
        int prefixLength = -1;
        NetworkInterface ni = NetworkInterface.getByInetAddress(addr);
        for (InterfaceAddress iaddr : ni.getInterfaceAddresses()) {
            if (iaddr.getAddress() instanceof Inet4Address) {
                prefixLength = iaddr.getNetworkPrefixLength();
                break;
            }
        }
        if (-1 == prefixLength) {
            return def;
        }

        byte[] ipRaw = addr.getAddress();
        // For ipv4
        if (4 == ipRaw.length) {
            int counter = prefixLength;
            for (int i = 0; i < ipRaw.length; i++) {
                if (counter < 8) {
                    byte mask = 0x00;
                    for (int j = 0; j < counter; j++) {
                        mask = (byte) (mask >> 1 | 0x80);
                    }
                    ipRaw[i] = (byte) (ipRaw[i] & mask);
                }
                counter -= 8;
            }

            // Re-format/round up hostAddress
            if (hostAddress < 0) {
                hostAddress += Math.pow(2, 32 - prefixLength);
            }

            // Add host address part
            int part = 4;
            while (hostAddress > 0 && part > 0) {
                ipRaw[part - 1] += (hostAddress & 0xff);
                hostAddress >>= 8;
            }
            return Inet4Address.getByAddress(ipRaw).getHostAddress();
        }
        // TODO Support ipv6?
    } catch (UnknownHostException | SocketException e) {
        m_log.debug(e);
    }
    return def;
}

From source file:eu.cassandra.utils.Utils.java

/**
 * This function is estimating the absolute euclidean distance of the active
 * and reactive power vector distance of two points of interest in the form of
 * arrays.//  w w  w . j a v a 2s  .c  om
 * 
 * @param a1
 *          The first array of values
 * @param a2
 *          The second array of values
 * 
 * @return the estimated absolute euclidean distance.
 */
public static double absoluteEuclideanDistance(double[] a1, double[] a2) {
    return Math.sqrt(Math.pow(a1[0] - a2[0], 2) + Math.pow(a1[1] - a2[1], 2));
}

From source file:com.civprod.writerstoolbox.testarea.UnsupervisedDiscourseSegmentation.java

public static double cosineSimilarityStemmedAndFiltered(Counter<String> countA, Counter<String> countB) {
    Set<String> allWords = countA.keySet().parallelStream()
            .filter((String curKey) -> countB.keySet().contains(curKey)).collect(Collectors.toSet());
    double dotProduct = allWords.parallelStream()
            .mapToDouble((String curKey) -> countA.getCount(curKey) * countB.getCount(curKey)).sum();
    double sqrtOfSumA = Math
            .pow(countA.keySet().parallelStream().mapToDouble((String curKey) -> countA.getCount(curKey))
                    .map((double curValue) -> curValue * curValue).sum(), .5);
    double sqrtOfSumB = Math
            .pow(countB.keySet().parallelStream().mapToDouble((String curKey) -> countB.getCount(curKey))
                    .map((double curValue) -> curValue * curValue).sum(), .5);
    return dotProduct / (sqrtOfSumA * sqrtOfSumB);
}

From source file:me.whitmarbut.mfa.TOTP.java

private String getToken(byte[] hmac) {
    int offset = hmac[19] & 0xf;

    Integer token = (int) ((((hmac[offset] & 0x7f) << 24) | ((hmac[offset + 1] & 0xff) << 16)
            | ((hmac[offset + 2] & 0xff) << 8) | (hmac[offset + 3] & 0xff)) % (Math.pow(10, 6)));
    String token_str = token.toString();
    if (token_str.length() < 6) {
        int to_add = 6 - token_str.length();
        for (int i = 0; i < to_add; i++) {
            token_str = "0" + token_str;
        }/*www .  j av  a  2s.c om*/
    }

    return token_str;
}