Example usage for org.apache.commons.math3.util FastMath acosh

List of usage examples for org.apache.commons.math3.util FastMath acosh

Introduction

In this page you can find the example usage for org.apache.commons.math3.util FastMath acosh.

Prototype

public static double acosh(final double a) 

Source Link

Document

Compute the inverse hyperbolic cosine of a number.

Usage

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Cheb.java

public static double[] cheb(int n, double[] x) {

    if (n <= 0) {
        throw new IllegalArgumentException("cheb: n has to be a positive integer");
    }//from www.  j  a va 2 s.c  om

    if (x.length == 0) {
        return new double[0];
    }
    //# avoid resizing latencies
    double[] T = new double[x.length];
    for (int i = 0; i < x.length; i++) {
        if (Math.abs(x[i]) > 1) {
            T[i] = FastMath.cos(n * FastMath.acos(x[i]));
        } else {
            T[i] = FastMath.cosh(n * FastMath.acosh(x[i]));
        }
    }
    return T;
}

From source file:com.rapidminer.tools.expression.internal.function.trigonometric.ArcHyperbolicCosine.java

@Override
protected double compute(double value) {
    return Double.isNaN(value) ? Double.NaN : FastMath.acosh(value);
}

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

private void calcCheb2Ord(double[] Wp, double[] Ws, double Rp, double Rs) {
    double T = 2;

    // returned frequency is the same as the input frequency
    Wc = Arrays.copyOf(Ws, Ws.length);

    // warp the target frequencies according to the bilinear transform
    for (int i = 0; i < Wp.length; i++) {
        Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T);
        Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T);
    }/*from  w  ww .j a  v  a 2  s .  c  o m*/
    double Wa;

    if (Wp[0] < Ws[0]) {
        // low pass
        if (Wp.length == 1) {
            Wa = Wp[0] / Ws[0];
        } else {
            // band reject
            throw new RuntimeException("band reject is not implement yet.");
        }
    } else {
        // if high pass, reverse the sense of the test
        if (Wp.length == 1) {
            Wa = Ws[0] / Wp[0];
        } else {
            // band pass 
            Wa = Double.MAX_VALUE;
            for (int i = 0; i < Wp.length; i++) {
                Wa = Math.min(Wa, Math.abs((Math.pow(Wp[i], 2) - Ws[0] * Ws[1]) / (Wp[i] * (Ws[0] - Ws[1]))));
            }
        }
    }

    // compute minimum n which satisfies all band edge conditions
    final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0);
    final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0);
    n = (int) Math.ceil(
            FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(1.0 / Wa));

}

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

private void calcCheb1Ord(double[] Wp, double[] Ws, double Rp, double Rs) {

    double T = 2;

    // returned frequency is the same as the input frequency
    Wc = Arrays.copyOf(Wp, Wp.length);

    // warp the target frequencies according to the bilinear transform
    for (int i = 0; i < Wp.length; i++) {
        Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T);
        Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T);
    }/* w w w. j  av a  2 s .c o  m*/
    double Wa;
    if (Wp[0] < Ws[0]) // low pass
    {
        if (Wp.length == 1) {
            Wa = Ws[0] / Wp[0];
        } else {
            // band reject
            throw new RuntimeException("band reject is not implement yet.");
        }
    } else {
        // if high pass, reverse the sense of the test
        if (Wp.length == 1) {
            Wa = Wp[0] / Ws[0];
        } else {
            // band pass
            Wa = Double.MAX_VALUE;
            for (int i = 0; i < Wp.length; i++) {
                Wa = Math.min(Wa, Math.abs((Math.pow(Ws[i], 2) - Wp[0] * Wp[1]) / (Ws[i] * (Wp[0] - Wp[1]))));
            }
        }
    }

    // compute minimum n which satisfies all band edge conditions
    final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0);
    final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0);
    n = (int) Math
            .ceil(FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(Wa));

}

From source file:lambertmrev.Lambert.java

public double x2tof2(double x, int N, double m_lambda) {
    double a = 1.0 / (1.0 - x * x);
    double tof;/*  w w  w.j  a v a  2  s. co  m*/
    if (a > 0) //ellipse
    {
        double alfa = 2.0 * FastMath.acos(x);
        double beta = 2.0 * FastMath.asin(FastMath.sqrt(m_lambda * m_lambda / a));
        if (m_lambda < 0.0)
            beta = -beta;
        tof = ((a * FastMath.sqrt(a)
                * ((alfa - FastMath.sin(alfa)) - (beta - FastMath.sin(beta)) + 2.0 * FastMath.PI * N)) / 2.0);
    } else {
        double alfa = 2.0 * FastMath.acosh(x);
        double beta = 2.0 * FastMath.asinh(FastMath.sqrt(-m_lambda * m_lambda / a));
        if (m_lambda < 0.0)
            beta = -beta;
        tof = (-a * FastMath.sqrt(-a) * ((beta - FastMath.sinh(beta)) - (alfa - FastMath.sinh(alfa))) / 2.0);
    }
    return tof;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the hyperbolic arc cosine of the number.
 * //from  ww  w  . j a va2s  . c  o  m
 * @param a the number
 * @return the hyperbolic arc cosine of the number
 * @see FastMath#acosh(double)
 */
public static Number acosh(Number a) {
    return FastMath.acosh(a.doubleValue());
}

From source file:de.tuberlin.uebb.jbop.example.DSCompilerOnlyCompose.java

@Override
public void acosh(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    final double x = operand[0];
    function[0] = FastMath.acosh(x);
    if (order > 0) {
        // the nth order derivative of acosh has the form:
        // dn(acosh(x)/dxn = P_n(x) / [x^2 - 1]^((2n-1)/2)
        // where P_n(x) is a degree n-1 polynomial with same parity as n-1
        // P_1(x) = 1, P_2(x) = -x, P_3(x) = 2x^2 + 1 ...
        // the general recurrence relation for P_n is:
        // P_n(x) = (x^2-1) P_(n-1)'(x) - (2n-3) x P_(n-1)(x)
        // as per polynomial parity, we can store coefficients of both P_(n-1) and P_n in the same array
        final double[] p = new double[order];
        p[0] = 1;/* www  .  j av a2  s .c om*/
        final double x2 = x * x;
        final double f = 1.0 / (x2 - 1);
        double coeff = FastMath.sqrt(f);
        function[1] = coeff * p[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial P_n(x)
            double v = 0;
            p[n - 1] = (1 - n) * p[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = (v * x2) + p[k];
                if (k > 2) {
                    p[k - 2] = ((1 - k) * p[k - 1]) + ((k - (2 * n)) * p[k - 3]);
                } else if (k == 2) {
                    p[0] = -p[1];
                }
            }
            if ((n & 0x1) == 0) {
                v *= x;
            }

            coeff *= f;
            function[n] = coeff * v;

        }
    }

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

}

From source file:de.tuberlin.uebb.jbop.example.DSCompiler.java

@Override
@Optimizable//from www . jav a 2 s  . c om
@StrictLoops
public void acosh(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    final double x = operand[0];
    function[0] = FastMath.acosh(x);
    if (order > 0) {
        // the nth order derivative of acosh has the form:
        // dn(acosh(x)/dxn = P_n(x) / [x^2 - 1]^((2n-1)/2)
        // where P_n(x) is a degree n-1 polynomial with same parity as n-1
        // P_1(x) = 1, P_2(x) = -x, P_3(x) = 2x^2 + 1 ...
        // the general recurrence relation for P_n is:
        // P_n(x) = (x^2-1) P_(n-1)'(x) - (2n-3) x P_(n-1)(x)
        // as per polynomial parity, we can store coefficients of both P_(n-1) and P_n in the same array
        final double[] p = new double[order];
        p[0] = 1;
        final double x2 = x * x;
        final double f = 1.0 / (x2 - 1);
        double coeff = FastMath.sqrt(f);
        function[1] = coeff * p[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial P_n(x)
            double v = 0;
            p[n - 1] = (1 - n) * p[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = (v * x2) + p[k];
                if (k > 2) {
                    p[k - 2] = ((1 - k) * p[k - 1]) + ((k - (2 * n)) * p[k - 3]);
                } else if (k == 2) {
                    p[0] = -p[1];
                }
            }
            if ((n & 0x1) == 0) {
                v *= x;
            }

            coeff *= f;
            function[n] = coeff * v;

        }
    }

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

}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void acoshInt() {
    try {/*  w w w .  j a va2 s .c o m*/
        Expression expression = getExpressionWithFunctionContext("acosh(16)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.acosh(16), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void acoshDouble() {
    try {//from  ww w.j  ava 2  s .c  o  m
        Expression expression = getExpressionWithFunctionContext("acosh(33.3)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.acosh(33.3), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}