Esempio n. 1
0
  @Test
  public void testRoot_6args() {
    System.out.println("root");
    double eps = 1e-15;
    double result = Zeroin.root(eps, -PI / 2, PI / 2, 0, sinF);
    assertEquals(0, result, eps);

    result = Zeroin.root(eps, -PI / 2, PI / 2, 0, sinFp1, 0.0, 1.0);
    assertEquals(-1.0, result, eps);

    result = Zeroin.root(eps, -PI / 2, PI / 2, 1, sinFp1, 3.0, 0.0);
    assertEquals(PI - 3.0, result, eps);

    result = Zeroin.root(eps, -6, 6, 0, polyF);
    assertEquals(-4.8790576334840479813, result, eps);
  }
Esempio n. 2
0
  /** Test of root method, of class Zeroin. */
  @Test
  public void testRoot_4args() {
    System.out.println("root");
    double eps = 1e-15;
    double result = Zeroin.root(-PI / 2, PI / 2, sinF);
    assertEquals(0, result, eps);

    result = Zeroin.root(-6, 6, polyF);
    assertEquals(-4.8790576334840479813, result, eps);

    result = Zeroin.root(-6, 6, polyF, 0);
    assertEquals(-4.8790576334840479813, result, eps);

    result = Zeroin.root(-PI / 2, PI / 2, sinFp1, 0.0, 1.0);
    assertEquals(-1.0, result, eps);

    try {
      result = Zeroin.root(-PI / 2, PI / 2, sinFp1);
      fail("Should not have run");
    } catch (Exception ex) {
    }
  }
  @Override
  protected double invCdf(final double p, final Function cdf) {
    if (p < 0 || p > 1)
      throw new ArithmeticException("Value of p must be in the range [0,1], not " + p);
    // we can't use the max/min b/c we might overflow on some of the computations, so lets tone it
    // down a little
    double a = Double.isInfinite(min()) ? Integer.MIN_VALUE * .95 : min();
    double b = Double.isInfinite(max()) ? Integer.MAX_VALUE * .95 : max();

    Function newCDF =
        new Function() {

          @Override
          public double f(double... x) {
            return cdf.f(x) - p;
          }

          @Override
          public double f(Vec x) {
            return f(x.get(0));
          }
        };
    return Zeroin.root(1e-6, a, b, newCDF, p);
  }