예제 #1
0
 /// <summary>
 /// Computes the complex Gamma function.
 /// </summary>
 /// <param name="z">The complex argument.</param>
 /// <returns>The complex value of &#x393;(z).</returns>
 /// <remarks>
 /// <para>The image below shows the complex &#x393; function near the origin using domain coloring.</para>
 /// <img src="../images/ComplexGammaPlot.png" />
 /// </remarks>
 /// <seealso cref="AdvancedMath.Gamma(double)"/>
 /// <seealso href="http://en.wikipedia.org/wiki/Gamma_function" />
 /// <seealso href="http://mathworld.wolfram.com/GammaFunction.html" />
 public static Complex Gamma(Complex z)
 {
     if (z.Re < 0.5)
     {
         // 1-z form
         return(Math.PI / Gamma(1.0 - z) / ComplexMath.Sin(Math.PI * z));
         // -z form
         //return (-Math.PI / Gamma(-z) / z / ComplexMath.Sin(Math.PI * z));
     }
     return(ComplexMath.Exp(LogGamma(z)));
 }
    static void Main(string[] args)
    {
        // usage
        ComplexNumber i = 2;
        ComplexNumber j = new ComplexNumber(1, -2);

        Console.WriteLine(i * j);
        Console.WriteLine(ComplexMath.Power(j, 2));
        Console.WriteLine((double)ComplexMath.Sin(i) + " vs " + Math.Sin(2));
        Console.WriteLine(ComplexMath.Power(j, 0) == 1.0);
    }
예제 #3
0
        public void Sin()
        {
            Complex      cd1 = new Complex(1.1, -2.2);
            Complex      cd2 = new Complex(0, -2.2);
            Complex      cd3 = new Complex(1.1, 0);
            Complex      cd4 = new Complex(-1.1, 2.2);
            ComplexFloat cf1 = new ComplexFloat(1.1f, -2.2f);
            ComplexFloat cf2 = new ComplexFloat(0, -2.2f);
            ComplexFloat cf3 = new ComplexFloat(1.1f, 0);
            ComplexFloat cf4 = new ComplexFloat(-1.1f, 2.2f);

            Complex cdt = ComplexMath.Sin(cd1);

            Assert.AreEqual(cdt.Real, 4.071, TOLERENCE);
            Assert.AreEqual(cdt.Imag, -2.022, TOLERENCE);

            cdt = ComplexMath.Sin(cd2);
            Assert.AreEqual(cdt.Real, 0, TOLERENCE);
            Assert.AreEqual(cdt.Imag, -4.457, TOLERENCE);

            cdt = ComplexMath.Sin(cd3);
            Assert.AreEqual(cdt.Real, 0.891, TOLERENCE);
            Assert.AreEqual(cdt.Imag, 0, TOLERENCE);

            cdt = ComplexMath.Sin(cd4);
            Assert.AreEqual(cdt.Real, -4.071, TOLERENCE);
            Assert.AreEqual(cdt.Imag, 2.022, TOLERENCE);

            ComplexFloat cft = ComplexMath.Sin(cf1);

            Assert.AreEqual(cft.Real, 4.071, TOLERENCE);
            Assert.AreEqual(cft.Imag, -2.022, TOLERENCE);

            cft = ComplexMath.Sin(cf2);
            Assert.AreEqual(cft.Real, 0, TOLERENCE);
            Assert.AreEqual(cft.Imag, -4.457, TOLERENCE);

            cft = ComplexMath.Sin(cf3);
            Assert.AreEqual(cft.Real, 0.891, TOLERENCE);
            Assert.AreEqual(cft.Imag, 0, TOLERENCE);

            cft = ComplexMath.Sin(cf4);
            Assert.AreEqual(cft.Real, -4.071, TOLERENCE);
            Assert.AreEqual(cft.Imag, 2.022, TOLERENCE);
        }
예제 #4
0
        public static Complex AiryAi_Asymptotic(Complex z)
        {
            Debug.Assert(ComplexMath.Abs(z) >= 9.0);

            if (z.Re >= 0.0)
            {
                Complex xi = 2.0 / 3.0 * ComplexMath.Pow(z, 3.0 / 2.0);
                Airy_Asymptotic_Subseries(xi, out Complex u0, out Complex v0, out Complex u1, out Complex v1);
                Complex e = ComplexMath.Exp(xi);
                Complex q = ComplexMath.Pow(z, 1.0 / 4.0);
                return(0.5 / Global.SqrtPI / q / e * u1);
            }
            else
            {
                z = -z;
                Complex xi = 2.0 / 3.0 * ComplexMath.Pow(z, 3.0 / 2.0);
                Airy_Asymptotic_Subseries(xi, out Complex u0, out Complex v0, out Complex u1, out Complex v1);
                Complex c = ComplexMath.Cos(xi);
                Complex s = ComplexMath.Sin(xi);

                throw new NotImplementedException();
            }
        }