public static ComplexNumber one () { return new ComplexNumber(1, 0); } public static ComplexNumber imgOne () { return new ComplexNumber(0, 1); } public static ComplexNumber zero () { return mew ComplexNumber(0, 0); }
public static ComplexNumber atan(ComplexNumber z) { ArgChecker.notNull(z, "z"); ComplexNumber iZ = ComplexMathUtils.multiply(z, I); ComplexNumber half = new ComplexNumber(0, 0.5); return ComplexMathUtils.multiply( half, ComplexMathUtils.log(ComplexMathUtils.divide(ComplexMathUtils.subtract(1, iZ), ComplexMathUtils.add(1, iZ)))); }
@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); }
@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); assertComplexEquals(z1, ComplexMathUtils.square(rZ1)); assertComplexEquals(z2, ComplexMathUtils.square(rZ2)); assertComplexEquals(z3, ComplexMathUtils.square(rZ3)); }
public static ComplexNumber pow(ComplexNumber z, double x) { double mod = mod(z); double arg = arg(z); double mult = Math.pow(mod, x); return new ComplexNumber(mult * Math.cos(x * arg), mult * Math.sin(x * arg)); }
public ComplexNumber add(ComplexNumber otherNumber){ ComplexNumber newComplex; float newA = a + otherNumber.getA(); float newB = b + otherNumber.getB(); newComplex = new ComplexNumber(newA, newB); return newComplex; }//end add
public static ComplexNumber pow(double x, ComplexNumber z) { ArgChecker.notNull(z, "z"); return pow(new ComplexNumber(x, 0), z); }
@Test public void testDivideMultiply() { assertComplexEquals(ComplexMathUtils.multiply(ComplexMathUtils.divide(Z1, Z2), Z2), Z1); assertComplexEquals(ComplexMathUtils.multiply(ComplexMathUtils.divide(Z1, X), X), Z1); assertComplexEquals(ComplexMathUtils.multiply(ComplexMathUtils.divide(X, Z1), Z1), X_C); assertComplexEquals(ComplexMathUtils.multiply(X, Z1), ComplexMathUtils.multiply(Z1, X)); }
@Test public void testAddSubtract() { assertComplexEquals(ComplexMathUtils.subtract(ComplexMathUtils.add(Z1, Z2), Z2), Z1); assertComplexEquals(ComplexMathUtils.subtract(ComplexMathUtils.add(Z1, X), X), Z1); assertComplexEquals(ComplexMathUtils.subtract(ComplexMathUtils.add(X, Z1), Z1), X_C); }
@Test public void testExpLn() { assertComplexEquals(ComplexMathUtils.log(ComplexMathUtils.exp(Z1)), Z1); //TODO test principal value }
@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); }
/** * If $y > 25$, this returns $b$. If $y < -25$ returns $a$. * {@inheritDoc} */ @Override public double inverseTransform(double y) { if (y > TANH_MAX) { return _upper; } else if (y < -TANH_MAX) { return _lower; } return _mid + _scale * TrigonometricFunctionUtils.tanh(y); }
@Override public Double apply(final Double x) { return FunctionUtils.square((x - 50) / 50.0); } };
@Test public void testInverse() { assertComplexEquals(ComplexMathUtils.inverse(ComplexMathUtils.inverse(Z1)), Z1); }
@Test public void testConjugate() { assertComplexEquals(ComplexMathUtils.conjugate(ComplexMathUtils.conjugate(Z1)), Z1); }
/** * Checks if two double precision floating point numbers are approximately "equal" * Default values are used for tolerances * @param val1 the first value * @param val2 the second value * @return true if they are considered equal, else false */ public static boolean SingleValueFuzzyEquals(double val1, double val2) { return SingleValueFuzzyEquals(val1, val2, default_tolerance, default_tolerance); }
/** * Checks if two double precision floating point array of arrays are approximately "equal" * Equal means the arrays have values the are considered fuzzy equals appearing in the same order and the arrays the same dimension. * Default values are used for tolerances. * @param arr1 the first value * @param arr2 the second value * @return true if they are considered equal, else false */ public static boolean ArrayFuzzyEquals(double[][] arr1, double[][] arr2) { return ArrayFuzzyEquals(arr1, arr2, default_tolerance, default_tolerance); }