public void ComplexTrigPeriodicity() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 8)) { Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(z), ComplexMath.Sin(z + 2.0 * Math.PI))); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(z), ComplexMath.Cos(z + 2.0 * Math.PI))); } }
public void ComplexTrigSpecialCases() { Assert.IsTrue(ComplexMath.Sin(0.0) == Complex.Zero); Assert.IsTrue(ComplexMath.Cos(0.0) == Complex.One); Assert.IsTrue(ComplexMath.Tan(0.0) == Complex.Zero); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(Math.PI / 2.0), 1.0, TestUtilities.RelativeTarget)); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Tan(Math.PI / 4.0), 1.0, TestUtilities.RelativeTarget)); }
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))); } }
public void ComplexTrigExtremeValues() { Assert.IsTrue(Complex.IsNaN(ComplexMath.Sin(Double.PositiveInfinity))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Sin(Double.NegativeInfinity))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Sin(Double.NaN))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Cos(Double.PositiveInfinity))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Cos(Double.NegativeInfinity))); Assert.IsTrue(Complex.IsNaN(ComplexMath.Cos(Double.NaN))); }
public void ComplexArcTrigInversion() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 32)) { Complex asin = ComplexMath.Asin(z); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(asin), z)); Complex acos = ComplexMath.Acos(z); Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(acos), z)); Assert.IsTrue(TestUtilities.IsSumNearlyEqual(asin, acos, Math.PI / 2.0)); } }
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 ComplexSecTanTest() { foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 10)) { 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 } Complex sec = 1.0 / ComplexMath.Cos(z); Complex tan = ComplexMath.Tan(z); Assert.IsTrue(TestUtilities.IsSumNearlyEqual(sec * sec, -tan * tan, 1)); } }
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 ComplexPythagorean() { 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 } Complex sin = ComplexMath.Sin(z); Complex cos = ComplexMath.Cos(z); Console.WriteLine("z={0} s={1} c={2} s^2+c^2={3}", z, sin, cos, sin * sin + cos * cos); Assert.IsTrue(TestUtilities.IsSumNearlyEqual(sin * sin, cos * cos, 1.0)); } }
public void ComplexSecTanTest() { 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; } Complex sec = 1.0 / ComplexMath.Cos(z); Complex tan = ComplexMath.Tan(z); Assert.IsTrue(TestUtilities.IsSumNearlyEqual(sec * sec, -tan * tan, 1)); } }
public void ComplexTrigPythagorean() { 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; } Complex sin = ComplexMath.Sin(z); Complex cos = ComplexMath.Cos(z); Console.WriteLine("z={0} s={1} c={2} s^2+c^2={3}", z, sin, cos, sin * sin + cos * cos); Assert.IsTrue(TestUtilities.IsSumNearlyEqual(sin * sin, cos * cos, 1.0)); } }
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 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)))); } }