Package com.opengamma.analytics.math.number

Examples of com.opengamma.analytics.math.number.ComplexNumber


    if (n % 2 != 0) {
      throw new IllegalArgumentException("Had an odd number of entries: should be impossible");
    }
    final ComplexNumber[] z = new ComplexNumber[n / 2];
    for (int i = 0; i < n; i += 2) {
      z[i / 2] = new ComplexNumber(a[i], a[i + 1]);
    }
    return z;
  }
View Full Code Here


  private static ComplexNumber[] unpack(final double[] a) {
    final int n = a.length;
    if (n % 2 == 0) {
      final int m = n / 2 + 1;
      final ComplexNumber[] z = new ComplexNumber[m];
      z[0] = new ComplexNumber(a[0]);
      z[n / 2] = new ComplexNumber(a[1]);
      for (int i = 1; i < n / 2; i++) {
        z[i] = new ComplexNumber(a[i * 2], a[i * 2 + 1]);
      }
      return z;
    }

    final int m = (n - 1) / 2 + 1;
    final ComplexNumber[] z = new ComplexNumber[m];
    z[0] = new ComplexNumber(a[0]);
    z[m - 1] = new ComplexNumber(a[n - 1], a[1]);
    for (int i = 1; i < m - 2; i++) {
      z[i] = new ComplexNumber(a[i * 2], a[i * 2 + 1]);
    }
    return z;

  }
View Full Code Here

  @Test
  public void testExpectation() {
    final double mu = 0.05;
    final double sigma = 0.2;
    final CharacteristicExponent ce = new GaussianCharacteristicExponent(mu, sigma);
    final ComplexNumber res = ce.getValue(MINUS_I,1.0);
    assertEquals(mu + 0.5 * sigma * sigma, res.getReal(), 1e-12);
    assertEquals(0.0, res.getImaginary(), 1e-12);
  }
View Full Code Here

 
  @Test
  public void testMeanCorrectedExpectation() {
    final double sigma = 0.2;
    final MartingaleCharacteristicExponent ce = new GaussianMartingaleCharacteristicExponent(sigma);
    final ComplexNumber res = ce.getFunction(1.0).evaluate(new ComplexNumber(0, -1));
    assertEquals(0.0, res.getReal(), 1e-12);
    assertEquals(0.0, res.getImaginary(), 1e-12);
  }
View Full Code Here

  @Test
  public void testCubic() {
    ComplexNumber[] result = CUBIC.getRoots(ONE_REAL_ROOT);
    assertEquals(result.length, 3);
    assertComplexEquals(result[0], new ComplexNumber(1, 0));
    assertComplexEquals(result[1], new ComplexNumber(0, Math.sqrt(10 / 3.)));
    assertComplexEquals(result[2], new ComplexNumber(0, -Math.sqrt(10 / 3.)));
    result = CUBIC.getRoots(ONE_DISTINCT_ROOT);
    assertEquals(result.length, 3);
    for (final ComplexNumber c : result) {
      assertComplexEquals(c, new ComplexNumber(1, 0));
    }
    result = CUBIC.getRoots(THREE_ROOTS);
    assertEquals(result.length, 3);
    assertComplexEquals(result[0], new ComplexNumber(1, 0));
    assertComplexEquals(result[1], new ComplexNumber(3, 0));
    assertComplexEquals(result[2], new ComplexNumber(2, 0));
  }
View Full Code Here

    assertComplexEquals(ComplexMathUtils.multiply(X, Z1), ComplexMathUtils.multiply(Z1, X));
  }

  @Test
  public void testMultiplyMany() {
    ComplexNumber a = multiply(Z1, multiply(Z2, Z1));
    ComplexNumber b = multiply(Z1, Z2, Z1);
    assertComplexEquals(a, b);
    double x = 3.142;
    ComplexNumber c = multiply(a, x);
    ComplexNumber d = multiply(x, Z1, Z1, Z2);
    assertComplexEquals(c, d);
  }
View Full Code Here

    assertEquals(Math.sqrt(V * V + W * W), ComplexMathUtils.mod(Z1), EPS);
  }

  @Test
  public void testPower() {
    assertComplexEquals(ComplexMathUtils.pow(Z1, 0), new ComplexNumber(1, 0));
    assertComplexEquals(ComplexMathUtils.pow(X, new ComplexNumber(0, 0)), new ComplexNumber(1, 0));
    assertComplexEquals(ComplexMathUtils.sqrt(ComplexMathUtils.pow(Z1, 2)), Z1);
    assertComplexEquals(ComplexMathUtils.sqrt(ComplexMathUtils.pow(Z2, 2)), Z2);
    assertComplexEquals(ComplexMathUtils.pow(ComplexMathUtils.pow(Z1, 1. / 3), 3), Z1);
    assertComplexEquals(ComplexMathUtils.pow(ComplexMathUtils.pow(X, ComplexMathUtils.inverse(Z2)), Z2), new ComplexNumber(X, 0));
    assertComplexEquals(ComplexMathUtils.pow(ComplexMathUtils.pow(Z1, ComplexMathUtils.inverse(Z2)), Z2), Z1);
  }
View Full Code Here

    assertComplexEquals(ComplexMathUtils.pow(ComplexMathUtils.pow(Z1, ComplexMathUtils.inverse(Z2)), Z2), Z1);
  }

  @Test
  public void testSqrt() {
    ComplexNumber z1 = new ComplexNumber(3, -2);
    ComplexNumber z2 = new ComplexNumber(-3, 4);
    ComplexNumber z3 = new ComplexNumber(-3, -4);

    ComplexNumber rZ1 = ComplexMathUtils.sqrt(z1);
    ComplexNumber rZ2 = ComplexMathUtils.sqrt(z2);
    ComplexNumber rZ3 = ComplexMathUtils.sqrt(z3);

    assertComplexEquals(ComplexMathUtils.pow(z1, 0.5), rZ1);
    assertComplexEquals(ComplexMathUtils.pow(z2, 0.5), rZ2);
    assertComplexEquals(ComplexMathUtils.pow(z3, 0.5), rZ3);
View Full Code Here

  }
 
  @Test
  public void testAtanh() {
    double x = 0.76;
    ComplexNumber z = new ComplexNumber(x);
    double real = 0.5*Math.log((1+x)/(1-x));
    ComplexNumber res = TrigonometricFunctionUtils.atanh(z);
    assertEquals(real,res.getReal(),1e-15);
    assertEquals(0.0,res.getImaginary(),0);
  }
View Full Code Here

    final double[] realTransform = new double[N];
    final ComplexNumber[] complex = new ComplexNumber[N];
    for (int i = 0; i < N; i++) {
      realTransform[i] = transform[i].getReal();
      complex[i] = new ComplexNumber(A[i], 0);
      assertComplexEquals(inverse[i], new ComplexNumber(A[i], 0));
    }

    final ComplexNumber[] transformComplex = JTransformsWrapper.transform1DComplex(complex);
    assertEquals(N, transformComplex.length);
    inverse = JTransformsWrapper.fullInverseTransform1DReal(realTransform, true);
    assertEquals(N, inverse.length);
    for (int i = 0; i < N; i++) {
      assertComplexEquals(transform[i], transformComplex[i]);
      // The DFT of cos functions will generally contain imaginary parts unless it is symmetrically sampled
      assertComplexEquals(inverse[i], new ComplexNumber(A[i], 0));
    }
  }
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.number.ComplexNumber

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.