Exemplo n.º 1
0
  /**
   * <u>Berechnen des Kotangens der komplexen Zahl</u><br>
   *
   * @return R&uuml;ckgabe eines Objektes vom Typ Complex mit L&ouml;sung aus cot(<u>z</u>)
   */
  public Complex cot() {
    double nn =
        Math.pow(Math.sin(this.real) * Math.cosh(this.imag), 2)
            + Math.pow(Math.cos(this.real) * Math.sinh(this.imag), 2);

    return new Complex(
        (Math.cos(this.real) * Math.sin(this.real)) / nn,
        (Math.cosh(this.imag) * Math.sinh(this.imag)) / nn);
  }
Exemplo n.º 2
0
  /**
   * <u>Berechnen des Kotangens der komplexen Zahl</u><br>
   *
   * @param comp Komplexe Zahl
   * @return R&uuml;ckgabe eines Objektes vom Typ Complex mit L&ouml;sung aus cot(<u>z</u>)
   */
  public static Complex cot(Complex comp) {
    double nn =
        Math.pow(Math.sin(comp.real) * Math.cosh(comp.imag), 2)
            + Math.pow(Math.cos(comp.real) * Math.sinh(comp.imag), 2);

    return new Complex(
        (Math.cos(comp.real) * Math.sin(comp.real)) / nn,
        (Math.cosh(comp.imag) * Math.sinh(comp.imag)) / nn);
  }
Exemplo n.º 3
0
 @Test
 public void testCosh() {
   for (double doubleValue : DOUBLE_VALUES) {
     assertFunction("cosh(" + doubleValue + ")", DOUBLE, Math.cosh(doubleValue));
   }
   assertFunction("cosh(NULL)", DOUBLE, null);
 }
Exemplo n.º 4
0
  /**
   * @param args the function arguments which must be either one object of type Double or Long
   * @return the result of the function evaluation which is the natural logarithm of the first
   *     argument
   */
  public Object evaluateFunction(final Object[] args) {
    final double angleInRadians;
    try {
      angleInRadians = FunctionUtil.getArgAsDouble(args[0]);
    } catch (final Exception e) {
      throw new IllegalArgumentException(
          "can't convert \"" + args[0] + "\" to an angle in radians in a call to TANH().");
    }

    return Math.sinh(angleInRadians) / Math.cosh(angleInRadians);
  }
Exemplo n.º 5
0
  /**
   * draws the inside of the hyperobola part
   *
   * @param center center
   * @param v1 1st eigenvector
   * @param v2 2nd eigenvector
   * @param a 1st eigenvalue
   * @param b 2nd eigenvalue
   * @param tMin t min
   * @param tMax t max
   */
  public void hyperbolaPart(
      Coords center, Coords v1, Coords v2, double a, double b, double tMin, double tMax) {

    manager.startGeometry(Manager.Type.TRIANGLE_FAN);

    manager.texture(0, 0);
    manager.normal(v1.crossProduct(v2));

    int longitude = manager.getLongitudeDefault();

    Coords m;

    float dt = (float) (tMax - tMin) / longitude;

    float u, v;

    // first point on the branch
    u = (float) Math.cosh(tMin);
    v = (float) Math.sinh(tMin);
    m = v1.mul(a * u).add(v2.mul(b * v));

    // center of the fan is midpoint of branch ends
    u = (float) Math.cosh(tMax);
    v = (float) Math.sinh(tMax);
    manager.triangleFanApex(center.add((m.add(v1.mul(a * u).add(v2.mul(b * v)))).mul(0.5)));

    // first point
    manager.triangleFanVertex(center.add(m));

    for (int i = 1; i <= longitude; i++) {
      u = (float) Math.cosh(tMin + i * dt);
      v = (float) Math.sinh(tMin + i * dt);

      m = v1.mul(a * u).add(v2.mul(b * v));
      manager.triangleFanVertex(center.add(m));
    }

    manager.endGeometry();
  }
Exemplo n.º 6
0
 public LuaValue call(LuaValue arg) {
   switch (opcode) {
     case 0:
       return valueOf(Math.acos(arg.checkdouble()));
     case 1:
       return valueOf(Math.asin(arg.checkdouble()));
     case 2:
       return valueOf(Math.atan(arg.checkdouble()));
     case 3:
       return valueOf(Math.cosh(arg.checkdouble()));
     case 4:
       return valueOf(Math.exp(arg.checkdouble()));
     case 5:
       return valueOf(Math.log(arg.checkdouble()));
     case 6:
       return valueOf(Math.log10(arg.checkdouble()));
     case 7:
       return valueOf(Math.sinh(arg.checkdouble()));
     case 8:
       return valueOf(Math.tanh(arg.checkdouble()));
   }
   return NIL;
 }
Exemplo n.º 7
0
 protected double call(double d) {
   return Math.cosh(d);
 }
Exemplo n.º 8
0
 public RealNumber cosh() {
   return new RealNumber(Math.cosh(this.value));
 }
Exemplo n.º 9
0
 @Description("hyperbolic cosine")
 @ScalarFunction
 @SqlType(DoubleType.NAME)
 public static double cosh(@SqlType(DoubleType.NAME) double num) {
   return Math.cosh(num);
 }
Exemplo n.º 10
0
 // return a new Complex object whose value is the complex cosine of this
 public Complex cos() {
   return new Complex(Math.cos(re) * Math.cosh(im), -Math.sin(re) * Math.sinh(im));
 }
Exemplo n.º 11
0
  /**
   * Evaluates this function. The child node is evaluated, the result of which must be a numeric
   * type (one of Double, Float, Long, Integer). The hyperbolic cosine of this value becomes the
   * result of this method as a double value.
   *
   * @return hyperbolic cosine of the value returned by the child
   */
  @Override
  public Double evaluate() {
    Object c = getChild(0).evaluate();

    return Math.cosh(NumericUtils.asDouble(c));
  }
Exemplo n.º 12
0
  @Override
  public Object visit(RealUnaryExpression n, Void arg) {
    Double doubleObject = (Double) n.getOperand().accept(this, null);
    double doubleVal = doubleObject.doubleValue();

    Operator op = n.getOperator();
    switch (op) {
      case ABS:
        return Math.abs(doubleVal);
      case ACOS:
        return Math.acos(doubleVal);
      case ASIN:
        return Math.asin(doubleVal);
      case ATAN:
        return Math.atan(doubleVal);
      case CBRT:
        return Math.cbrt(doubleVal);
      case CEIL:
        return Math.ceil(doubleVal);
      case COS:
        return Math.cos(doubleVal);
      case COSH:
        return Math.cosh(doubleVal);
      case EXP:
        return Math.exp(doubleVal);
      case EXPM1:
        return Math.expm1(doubleVal);
      case FLOOR:
        return Math.floor(doubleVal);
      case LOG:
        return Math.log(doubleVal);
      case LOG10:
        return Math.log10(doubleVal);
      case LOG1P:
        return Math.log1p(doubleVal);
      case NEG:
        return -doubleVal;
      case NEXTUP:
        return Math.nextUp(doubleVal);
      case RINT:
        return Math.rint(doubleVal);
      case SIGNUM:
        return Math.signum(doubleVal);
      case SIN:
        return Math.sin(doubleVal);
      case SINH:
        return Math.sinh(doubleVal);
      case SQRT:
        return Math.sqrt(doubleVal);
      case TAN:
        return Math.tan(doubleVal);
      case TANH:
        return Math.tanh(doubleVal);
      case TODEGREES:
        return Math.toDegrees(doubleVal);
      case TORADIANS:
        return Math.toRadians(doubleVal);
      case ULP:
        return Math.ulp(doubleVal);

      default:
        log.warn("RealUnaryExpression: unimplemented operator: " + op);
        return null;
    }
  }
Exemplo n.º 13
0
 // To add/remove functions change evaluateOperator() and registration
 public double evaluateFunction(String fncnam, ArgParser fncargs) throws ArithmeticException {
   switch (Character.toLowerCase(fncnam.charAt(0))) {
     case 'a':
       {
         if (fncnam.equalsIgnoreCase("abs")) {
           return Math.abs(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("acos")) {
           return Math.acos(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("asin")) {
           return Math.asin(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("atan")) {
           return Math.atan(fncargs.next());
         }
       }
       break;
     case 'c':
       {
         if (fncnam.equalsIgnoreCase("cbrt")) {
           return Math.cbrt(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("ceil")) {
           return Math.ceil(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("cos")) {
           return Math.cos(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("cosh")) {
           return Math.cosh(fncargs.next());
         }
       }
       break;
     case 'e':
       {
         if (fncnam.equalsIgnoreCase("exp")) {
           return Math.exp(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("expm1")) {
           return Math.expm1(fncargs.next());
         }
       }
       break;
     case 'f':
       {
         if (fncnam.equalsIgnoreCase("floor")) {
           return Math.floor(fncargs.next());
         }
       }
       break;
     case 'g':
       {
         //              if(fncnam.equalsIgnoreCase("getExponent"   )) { return
         // Math.getExponent(fncargs.next());                } needs Java 6
       }
       break;
     case 'l':
       {
         if (fncnam.equalsIgnoreCase("log")) {
           return Math.log(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("log10")) {
           return Math.log10(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("log1p")) {
           return Math.log1p(fncargs.next());
         }
       }
       break;
     case 'm':
       {
         if (fncnam.equalsIgnoreCase("max")) {
           return Math.max(fncargs.next(), fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("min")) {
           return Math.min(fncargs.next(), fncargs.next());
         }
       }
       break;
     case 'n':
       {
         //              if(fncnam.equalsIgnoreCase("nextUp"        )) { return Math.nextUp
         // (fncargs.next());                } needs Java 6
       }
       break;
     case 'r':
       {
         if (fncnam.equalsIgnoreCase("random")) {
           return Math.random();
         } // impure
         if (fncnam.equalsIgnoreCase("round")) {
           return Math.round(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("roundHE")) {
           return Math.rint(fncargs.next());
         } // round half-even
       }
       break;
     case 's':
       {
         if (fncnam.equalsIgnoreCase("signum")) {
           return Math.signum(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sin")) {
           return Math.sin(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sinh")) {
           return Math.sinh(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("sqrt")) {
           return Math.sqrt(fncargs.next());
         }
       }
       break;
     case 't':
       {
         if (fncnam.equalsIgnoreCase("tan")) {
           return Math.tan(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("tanh")) {
           return Math.tanh(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("toDegrees")) {
           return Math.toDegrees(fncargs.next());
         }
         if (fncnam.equalsIgnoreCase("toRadians")) {
           return Math.toRadians(fncargs.next());
         }
       }
       break;
     case 'u':
       {
         if (fncnam.equalsIgnoreCase("ulp")) {
           return Math.ulp(fncargs.next());
         }
       }
       break;
       // no default
   }
   throw new UnsupportedOperationException(
       "MathEval internal function setup is incorrect - internal function \""
           + fncnam
           + "\" not handled");
 }
Exemplo n.º 14
0
  /**
   * Evaluates the Jacobian elliptic functions sn(u|m), cn(u|m), and dn(u|m) of parameter m between
   * 0 and 1, and real argument u. (based on the function from the Cephes Math Library)
   *
   * @param u
   * @param m
   * @return an array containing the values of the functions sn(u|m), cn(u|m), dn(u|m) and phi, the
   *     amplitude of u
   */
  public static double[] calculateJacobianEllipticFunctionsValues(double u, double m) {

    double ai, b, phi, t, twon;
    double sn, cn, ph, dn;
    double[] a = new double[9];
    double[] c = new double[9];
    int i;

    // Check for special cases
    if (m < 0.0 || m > 1.0 || Double.isNaN(m))
      throw new IllegalArgumentException("m should be in <0,1>");
    if (m < 1.0e-9) {

      t = Math.sin(u);
      b = Math.cos(u);
      ai = 0.25 * m * (u - t * b);
      sn = t - ai * b;
      cn = b + ai * t;
      ph = u - ai;
      dn = 1.0 - 0.5 * m * t * t;
      return new double[] {sn, cn, dn, ph};
    }
    if (m >= 0.9999999999) {
      ai = 0.25 * (1.0 - m);
      b = Math.cosh(u);
      t = Math.tanh(u);
      phi = 1.0 / b;
      twon = b * Math.sinh(u);

      sn = t + ai * (twon - u) / (b * b);
      ph = 2.0 * Math.atan(Math.exp(u)) - Math.PI / 2 + ai * (twon - u) / b;
      ai *= t * phi;
      cn = phi - ai * (twon - u);
      dn = phi + ai * (twon + u);
      return new double[] {sn, cn, dn, ph};
    }

    //	A. G. M. scale
    a[0] = 1.0;
    b = Math.sqrt(1.0 - m);
    c[0] = Math.sqrt(m);
    twon = 1.0;
    i = 0;

    while (Math.abs(c[i] / a[i]) > getMachineEpsilon()) {

      if (i > 7)
        throw new IllegalArgumentException(
            "Jacobian elliptic functions cannot be calculated due to overflow range error");
      ai = a[i];
      i++;
      c[i] = (ai - b) / 2.0;
      t = Math.sqrt(ai * b);
      a[i] = (ai + b) / 2.0;
      b = t;
      twon *= 2.0;
    }

    // backward recurrence
    phi = twon * a[i] * u;
    do {

      t = c[i] * Math.sin(phi) / a[i];
      b = phi;
      phi = (Math.asin(t) + phi) / 2.0;
      i--;

    } while (i > 0);

    sn = Math.sin(phi);
    t = Math.cos(phi);
    cn = t;
    dn = t / Math.cos(phi - b);
    ph = phi;

    return new double[] {sn, cn, dn, ph};
  }
Exemplo n.º 15
0
 public static IntervalDouble math_cosh(IntervalDouble a) {
   IntervalDouble res =
       new IntervalDouble(Math.cosh(a.value), DoubleInterval.cosh(a.interval), a.isUnStable);
   return res;
 }
Exemplo n.º 16
0
 /**
  * <u>Berechnen der e-Funktion der komplexen Zahl</u><br>
  *
  * @return R&uuml;ckgabe eines Objektes vom Typ Complex mit L&ouml;sung aus exp(<u>z</u>)
  */
 public Complex exp() {
   return new Complex(
       Math.cos(this.getImag()) * (Math.sinh(this.getReal()) + Math.cosh(this.getReal())),
       Math.sin(this.getImag()) * (Math.cosh(this.getReal()) + Math.sinh(this.getReal())));
 }
 /** {@inheritDoc} */
 public OpenMapRealVector mapCoshToSelf() {
   for (int i = 0; i < virtualSize; i++) {
     setEntry(i, Math.cosh(getEntry(i)));
   }
   return this;
 }
Exemplo n.º 18
0
 /**
  * <u>Berechnen der e-Funktion der komplexen Zahl</u><br>
  *
  * @param comp Komplexe Zahl
  * @return R&uuml;ckgabe eines Objektes vom Typ Complex mit L&ouml;sung aus exp(<u>z</u>)
  */
 public static Complex exp(Complex comp) {
   return new Complex(
       Math.cos(comp.getImag()) * (Math.sinh(comp.getReal()) + Math.cosh(comp.getReal())),
       Math.sin(comp.getImag()) * (Math.cosh(comp.getReal()) + Math.sinh(comp.getReal())));
 }
Exemplo n.º 19
0
 public static double besselI(double nu, double x) {
   double next, sum, next1, next2, sum1, sum2, int1, int2, yp, y, yn, h;
   long m, N;
   if (x < 0) return Double.NaN;
   if ((nu < 0) && (Math.round(nu) == nu))
     if (((int) Math.round(nu)) % 2 == 1) return -besselI(-nu, x);
     else return besselI(-nu, x);
   if ((nu == 0.0) && (x == 0.0)) return 1.0;
   if (x == 0.0) return 0.0;
   // power series
   if ((x <= 15) || (x * x < 15 * nu)) {
     next = Math.pow(x / 2, nu) / eulergamma(nu + 1);
     sum = next;
     int max = (int) (40 * x);
     for (m = 1; m < 200; m++) {
       next *= (x * x / 4) / (m * (m + nu));
       sum += next;
     }
     return sum;
   } else if (8 * x > (nu * nu)) {
     // asymptotic expansion
     // if((x>30)&&(x>(3*(nu*nu-0.25)))){
     next1 = 1;
     sum1 = next1;
     // next2=(4*nu*nu-1)/(8*x);
     // sum2=next2;
     int max = 10 > nu ? 10 : (int) nu;
     for (m = 1; m <= max; m++) {
       next1 *= -(4 * nu * nu - (2 * m - 1) * (2 * m - 1)) / (m * 8 * x);
       sum1 += next1;
       // next2*=-(4*nu*nu-(4*m-1)*(4*m-1))*(4*nu*nu-(4*m+1)*(4*m+1))/(2*m*(2*m+1)*8*x*8*x);
       // sum2+=next2;
     }
     return Math.exp(x) / Math.sqrt(2 * pi * x) * sum1;
   }
   // integral
   N = (long) 40 * Math.round(x);
   h = pi / N;
   yp = Math.exp(x);
   y = Math.exp(x * Math.cos(h)) * Math.cos(nu * h);
   yn = Math.exp(x * Math.cos(2 * h)) * Math.cos(nu * 2 * h);
   int1 = h / 3 * (yp + 4 * y + yn);
   for (m = 3; m < N; m += 2) {
     yp = yn;
     y = Math.exp(x * Math.cos(m * h)) * Math.cos(nu * m * h);
     yn = Math.exp(x * Math.cos((m + 1) * h)) * Math.cos(nu * (m + 1) * h);
     int1 += h / 3 * (yp + 4 * y + yn);
   }
   if (nu == Math.round(nu)) return int1 / pi;
   h = 0.0004;
   yp = 1;
   y = Math.exp(-x * Math.cosh(h) - nu * h);
   yn = Math.exp(-x * Math.cosh(2 * h) - nu * h);
   int2 = h / 3 * (yp + 4 * y + yn);
   for (m = 3; m < 5000; m += 2) {
     yp = yn;
     y = Math.exp(-x * Math.cosh(m * h) - nu * m * h);
     yn = Math.exp(-x * Math.cosh((m + 1) * h) - nu * (m + 1) * h);
     int2 += h / 3 * (yp + 4 * y + yn);
   }
   return int1 / pi - Math.sin(nu * pi) * int2 / pi;
 }