/// <summary> /// Computes the complex digamma (ψ) function. /// </summary> /// <param name="z">The complex argument.</param> /// <returns>The value of ψ(z).</returns> /// <remarks> /// <para>The image below shows the complex ψ function near the origin using domain coloring.</para> /// <img src="../images/ComplexPsiPlot.png" /> /// </remarks> /// <seealso cref="AdvancedMath.Psi(double)" /> public static Complex Psi(Complex z) { if (z.Re < 0.5) { // reduce z.Re in order to handle large real values! return(Psi(1.0 - z) - Math.PI / ComplexMath.Tan(Math.PI * z)); } else { // add Stirling for large z return(Lanczos.Psi(z)); } }
public void Tan() { 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.Tan(cd1); Assert.AreEqual(cdt.Real, 0.020, TOLERENCE); Assert.AreEqual(cdt.Imag, -1.014, TOLERENCE); cdt = ComplexMath.Tan(cd2); Assert.AreEqual(cdt.Real, 0, TOLERENCE); Assert.AreEqual(cdt.Imag, -0.976, TOLERENCE); cdt = ComplexMath.Tan(cd3); Assert.AreEqual(cdt.Real, 1.965, TOLERENCE); Assert.AreEqual(cdt.Imag, 0, TOLERENCE); cdt = ComplexMath.Tan(cd4); Assert.AreEqual(cdt.Real, -0.020, TOLERENCE); Assert.AreEqual(cdt.Imag, 1.014, TOLERENCE); ComplexFloat cft = ComplexMath.Tan(cf1); Assert.AreEqual(cft.Real, 0.020, TOLERENCE); Assert.AreEqual(cft.Imag, -1.014, TOLERENCE); cft = ComplexMath.Tan(cf2); Assert.AreEqual(cft.Real, 0, TOLERENCE); Assert.AreEqual(cft.Imag, -0.976, TOLERENCE); cft = ComplexMath.Tan(cf3); Assert.AreEqual(cft.Real, 1.965, TOLERENCE); Assert.AreEqual(cft.Imag, 0, TOLERENCE); cft = ComplexMath.Tan(cf4); Assert.AreEqual(cft.Real, -0.020, TOLERENCE); Assert.AreEqual(cft.Imag, 1.014, TOLERENCE); }