public void ComplexExpSpecialValues() { Assert.IsTrue(ComplexMath.Exp(0.0) == Complex.One); Assert.IsTrue(ComplexMath.Exp(1.0) == Math.E); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Exp(Complex.I * Math.PI), -Complex.One)); }
public void ComplexLogExtremeValues() { Assert.IsTrue(ComplexMath.Log(Double.MaxValue) == Math.Log(Double.MaxValue)); Assert.IsTrue(Complex.IsNaN(ComplexMath.Log(Double.NaN))); }
public void ComplexLogSum() { Complex[] z = TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 10); for (int i = 0; i < z.Length; i++) { for (int j = 0; j < i; j++) { if (Math.Abs(ComplexMath.Arg(z[i]) + ComplexMath.Arg(z[j])) >= Math.PI) { continue; } Console.WriteLine("{0} {1}", z[i], z[j]); Console.WriteLine("ln(z1) + ln(z2) = {0}", ComplexMath.Log(z[i]) + ComplexMath.Log(z[j])); Console.WriteLine("ln(z1*z2) = {0}", ComplexMath.Log(z[i] * z[j])); Assert.IsTrue(TestUtilities.IsSumNearlyEqual(ComplexMath.Log(z[i]), ComplexMath.Log(z[j]), ComplexMath.Log(z[i] * z[j]))); } } }
public void ComplexSqrt() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 32)) { Complex sz = ComplexMath.Sqrt(z); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sqr(sz), z, TestUtilities.RelativeTarget)); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Arg(z) / 2.0, ComplexMath.Arg(sz), TestUtilities.RelativeTarget)); Assert.IsTrue(TestUtilities.IsNearlyEqual(Math.Sqrt(ComplexMath.Abs(z)), ComplexMath.Abs(sz), TestUtilities.RelativeTarget)); } }
public void ComplexPowMultiplication() { Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Pow(a, 2.0) * ComplexMath.Pow(a, 3.0), ComplexMath.Pow(a, 5.0))); }
public void Bug5504() { // this eigenvalue non-convergence is solved by an ad hoc shift // these "cyclic matrices" are good examples of situations that are difficult for the QR algorithm for (int d = 2; d <= 8; d++) { Console.WriteLine(d); SquareMatrix C = CyclicMatrix(d); Complex[] lambdas = C.Eigenvalues(); foreach (Complex lambda in lambdas) { Console.WriteLine("{0} ({1} {2})", lambda, ComplexMath.Abs(lambda), ComplexMath.Arg(lambda)); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Abs(lambda), 1.0)); } } }
public void ComplexExpSpecialCase() { Assert.IsTrue(ComplexMath.Exp(0.0) == 1.0); Assert.IsTrue(ComplexMath.Exp(1.0) == Math.E); }
public void ComplexAngleAdditionTest() { Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(a + b), ComplexMath.Sin(a) * ComplexMath.Cos(b) + ComplexMath.Cos(a) * ComplexMath.Sin(b)), String.Format("{0} != {1}", ComplexMath.Sin(a + b), ComplexMath.Sin(a) * ComplexMath.Cos(b) + ComplexMath.Cos(a) * ComplexMath.Sin(b))); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(a + b), ComplexMath.Cos(a) * ComplexMath.Cos(b) - ComplexMath.Sin(a) * ComplexMath.Sin(b))); }
public void ComplexHyperbolicTrigExtremeValues() { Assert.IsTrue(Complex.IsNaN(ComplexMath.Sinh(Double.NaN))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Cosh(Double.NaN))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Tanh(Double.NaN))); }
public void ComplexNegativeAngles() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 16)) { if (Math.Abs(z.Im) > Math.Log(Double.MaxValue / 10.0)) { continue; // sin and cos blow up in imaginary part of argument gets too big } Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(-z), -ComplexMath.Sin(z)), String.Format("remainder {0}", ComplexMath.Sin(-a) + ComplexMath.Sin(a))); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(-z), ComplexMath.Cos(z)), String.Format("{0} vs. {1}", ComplexMath.Cos(-a), ComplexMath.Cos(a))); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Tan(-z), -ComplexMath.Tan(z))); } }
public void ComplexIDefinition() { Assert.IsTrue(ComplexMath.Sqrt(-1.0) == Complex.I); }
public void ComplexDiLogSymmetry() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 12)) { Assert.IsTrue(TestUtilities.IsSumNearlyEqual( AdvancedComplexMath.DiLog(z), AdvancedComplexMath.DiLog(-z), AdvancedComplexMath.DiLog(z * z) / 2.0 )); Assert.IsTrue(TestUtilities.IsNearlyEqual( -AdvancedComplexMath.DiLog(1.0 / z), AdvancedComplexMath.DiLog(z) + ComplexMath.Log(-z) * ComplexMath.Log(-z) / 2.0 + Math.PI * Math.PI / 6.0 )); Assert.IsTrue(TestUtilities.IsNearlyEqual( -AdvancedComplexMath.DiLog(1.0 - z), AdvancedComplexMath.DiLog(z) + ComplexMath.Log(z) * ComplexMath.Log(1.0 - z) - Math.PI * Math.PI / 6.0 )); } }
public void ComplexGammaDuplicationTest() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 16)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(2.0 * z), ComplexMath.Pow(2.0, 2.0 * z - 0.5) * AdvancedComplexMath.Gamma(z) * AdvancedComplexMath.Gamma(z + 0.5) / Math.Sqrt(2.0 * Math.PI))); } }
public void ComplexDoubleAngle() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 16)) { if (Math.Abs(z.Im) > Math.Log(Double.MaxValue / 10.0)) { continue; } Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(2.0 * z), 2.0 * ComplexMath.Sin(z) * ComplexMath.Cos(z))); //Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(2.0 * z), ComplexMath.Sqr(ComplexMath.Cos(z)) - ComplexMath.Sqr(ComplexMath.Sin(z)))); } }
public void ComplexExpExtremeValues() { Assert.IsTrue(ComplexMath.Exp(Double.NegativeInfinity) == Complex.Zero); Assert.IsTrue(Complex.IsNaN(ComplexMath.Exp(Double.NaN))); }
public void ComplexCosCosh() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-3, 1.0E3, 16)) { // Since sin(z) and cos(z) have factors that go like e^{\pm Im(z)}, they will blow up if the imaginary // part of z gets too big. We just skip over those problematic values. if (Math.Abs(z.Im) > Math.Log(Double.MaxValue) / 2.0) { continue; } Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cosh(z), ComplexMath.Cos(ComplexMath.I * z))); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cosh(-ComplexMath.I * z), ComplexMath.Cos(z))); } }
public void ComplexPowExponent() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 6)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Pow(Math.E, z), ComplexMath.Exp(z))); } }
public void ComplexTanTanh() { foreach (Complex x in TestUtilities.GenerateComplexValues(1.0E-3, 1.0E3, 16)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Tanh(x), -ComplexMath.I * ComplexMath.Tan(ComplexMath.I * x))); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Tanh(-ComplexMath.I * x), -ComplexMath.I * ComplexMath.Tan(x))); } }
public void ComplexGammaInequality () { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 10)) { Console.WriteLine(z); Assert.IsTrue(ComplexMath.Abs(AdvancedComplexMath.Gamma(z)) <= Math.Abs(AdvancedMath.Gamma(z.Re))); } }
public void ComplexCosCosh() { foreach (Complex x in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 10)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cosh(x), ComplexMath.Cos(ComplexMath.I * x))); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cosh(-ComplexMath.I * x), ComplexMath.Cos(x))); } }