From 10c34deadf255ff887e3b9ad44bc379c71bfbf46 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Wed, 14 Aug 2013 18:55:24 +0200 Subject: [PATCH] Trig: sort members logically (instead of by name), no code changes --- src/Numerics/Trigonometry.cs | 748 +++++++++++++++++------------------ 1 file changed, 374 insertions(+), 374 deletions(-) diff --git a/src/Numerics/Trigonometry.cs b/src/Numerics/Trigonometry.cs index 99b321e7..32c93528 100644 --- a/src/Numerics/Trigonometry.cs +++ b/src/Numerics/Trigonometry.cs @@ -46,115 +46,6 @@ namespace MathNet.Numerics /// private const double DegreeToGradConstant = 10.0 / 9.0; - /// - /// Trigonometric Cosecant of an angle in radian. - /// - /// - /// The angle in radian. - /// - /// - /// Cosecant of an angle in radian. - /// - public static double Cosecant(double radian) - { - return 1 / Math.Sin(radian); - } - - /// - /// Trigonometric Cosecant of a Complex number. - /// - /// - /// The complex value. - /// - /// - /// The cosecant of a complex number. - /// - public static Complex Cosecant(this Complex value) - { - if (value.IsReal()) - { - return new Complex(Cosecant(value.Real), 0d); - } - - var sinr = Sine(value.Real); - var sinhi = HyperbolicSine(value.Imaginary); - var denom = (sinr * sinr) + (sinhi * sinhi); - - return new Complex(sinr * HyperbolicCosine(value.Imaginary) / denom, -Cosine(value.Real) * sinhi / denom); - } - - /// - /// Trigonometric Cosine of an angle in radian. - /// - /// - /// The angle in radian. - /// - /// - /// The cosine of an angle in radian. - /// - public static double Cosine(double radian) - { - return Math.Cos(radian); - } - - /// - /// Trigonometric Cosine of a Complex number. - /// - /// - /// The complex value. - /// - /// - /// The cosine of a complex number. - /// - public static Complex Cosine(this Complex value) - { - if (value.IsReal()) - { - return new Complex(Cosine(value.Real), 0.0); - } - - return new Complex( - Cosine(value.Real) * HyperbolicCosine(value.Imaginary), - -Sine(value.Real) * HyperbolicSine(value.Imaginary)); - } - - /// - /// Trigonometric Cotangent of an angle in radian. - /// - /// - /// The angle in radian. - /// - /// - /// The cotangent of an angle in radian. - /// - public static double Cotangent(double radian) - { - return 1 / Math.Tan(radian); - } - - /// - /// Trigonometric Cotangent of a Complex number. - /// - /// - /// The complex value. - /// - /// - /// The cotangent of the complex number. - /// - public static Complex Cotangent(this Complex value) - { - if (value.IsReal()) - { - return new Complex(Cotangent(value.Real), 0d); - } - - var sinr = Sine(value.Real); - var sinhi = HyperbolicSine(value.Imaginary); - var denom = (sinr * sinr) + (sinhi * sinhi); - - return new Complex(sinr * Cosine(value.Real) / denom, -sinhi * HyperbolicCosine(value.Imaginary) / denom); - } - /// /// Converts a degree (360-periodic) angle to a grad (400-periodic) angle. /// @@ -212,295 +103,282 @@ namespace MathNet.Numerics } /// - /// Trigonometric Hyperbolic Cosecant + /// Converts a radian (2*Pi-periodic) angle to a degree (360-periodic) angle. + /// + /// + /// The radian to convert. + /// + /// + /// The converted degree. + /// + public static double RadianToDegree(double radian) + { + return radian / Constants.Degree; + } + + /// + /// Converts a radian (2*Pi-periodic) angle to a grad (400-periodic) angle. + /// + /// + /// The radian to convert. + /// + /// + /// The converted grad. + /// + public static double RadianToGrad(double radian) + { + return radian / Constants.Grad; + } + + /// + /// Trigonometric Sine of an angle in radian /// /// /// The angle in radian. /// /// - /// The hyperbolic cosecant of the radian angle. + /// The sine of the radian angle. /// - public static double HyperbolicCosecant(double radian) + public static double Sine(double radian) { - return 1 / HyperbolicSine(radian); + return Math.Sin(radian); } /// - /// Trigonometric Hyperbolic Cosecant of a Complex number. + /// Trigonometric Sine of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic cosecant of a complex number. + /// The sine of the complex number. /// - public static Complex HyperbolicCosecant(this Complex value) + public static Complex Sine(this Complex value) { if (value.IsReal()) { - return new Complex(HyperbolicCosecant(value.Real), 0.0); - } - - var exp = value.Exponential(); - - if (exp.IsInfinity()) - { - return Complex.Zero; + return new Complex(Sine(value.Real), 0.0); } - return 2 * exp / (exp.Square() - 1); + return new Complex( + Sine(value.Real) * HyperbolicCosine(value.Imaginary), + Cosine(value.Real) * HyperbolicSine(value.Imaginary)); } /// - /// Trigonometric Hyperbolic Cosine + /// Trigonometric Cosine of an angle in radian. /// /// /// The angle in radian. /// /// - /// The hyperbolic Cosine of the radian angle. + /// The cosine of an angle in radian. /// - public static double HyperbolicCosine(double radian) + public static double Cosine(double radian) { - return (Math.Exp(radian) + Math.Exp(-radian)) / 2; + return Math.Cos(radian); } /// - /// Trigonometric Hyperbolic Cosine of a Complex number. + /// Trigonometric Cosine of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic cosine of a complex number. + /// The cosine of a complex number. /// - public static Complex HyperbolicCosine(this Complex value) + public static Complex Cosine(this Complex value) { if (value.IsReal()) { - return new Complex(HyperbolicCosine(value.Real), 0.0); + return new Complex(Cosine(value.Real), 0.0); } return new Complex( - HyperbolicCosine(value.Real) * Cosine(value.Imaginary), - HyperbolicSine(value.Real) * Sine(value.Imaginary)); + Cosine(value.Real) * HyperbolicCosine(value.Imaginary), + -Sine(value.Real) * HyperbolicSine(value.Imaginary)); } /// - /// Trigonometric Hyperbolic Cotangent + /// Trigonometric Tangent of an angle in radian /// /// - /// The angle in radian angle. + /// The angle in radian. /// /// - /// The hyperbolic cotangent of the radian angle. + /// The tangent of the radian angle. /// - public static double HyperbolicCotangent(double radian) + public static double Tangent(double radian) { - if (radian > 19.115) - { - return 1.0; - } - - if (radian < -19.115) - { - return -1; - } - - var e1 = Math.Exp(radian); - var e2 = Math.Exp(-radian); - return (e1 + e2) / (e1 - e2); + return Math.Tan(radian); } /// - /// Trigonometric Hyperbolic Cotangent of a Complex number. + /// Trigonometric Tangent of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic cotangent of a complex number. + /// The tangent of the complex number. /// - public static Complex HyperbolicCotangent(this Complex value) + public static Complex Tangent(this Complex value) { if (value.IsReal()) { - return new Complex(HyperbolicCotangent(value.Real), 0.0); - } - - var sini = Sine(value.Imaginary); - var sinhr = HyperbolicSine(value.Real); - - if (double.IsInfinity(sinhr)) - { - return new Complex(double.IsPositiveInfinity(sinhr) ? 1 : -1, 0.0); + return new Complex(Tangent(value.Real), 0.0); } - var denom = (sini * sini) + (sinhr * sinhr); + var cosr = Cosine(value.Real); + var sinhi = HyperbolicSine(value.Imaginary); + var denom = (cosr * cosr) + (sinhi * sinhi); - return new Complex(sinhr * HyperbolicCosine(value.Real) / denom, sini * Cosine(value.Imaginary) / denom); + return new Complex(Sine(value.Real) * cosr / denom, sinhi * HyperbolicCosine(value.Imaginary) / denom); } /// - /// Trigonometric Hyperbolic Secant + /// Trigonometric Cotangent of an angle in radian. /// /// - /// The angle in radian angle. + /// The angle in radian. /// /// - /// The hyperbolic secant of the radian angle. + /// The cotangent of an angle in radian. /// - public static double HyperbolicSecant(double radian) + public static double Cotangent(double radian) { - return 1 / HyperbolicCosine(radian); + return 1 / Math.Tan(radian); } /// - /// Trigonometric Hyperbolic Secant of a Complex number. + /// Trigonometric Cotangent of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic secant of a complex number. + /// The cotangent of the complex number. /// - public static Complex HyperbolicSecant(this Complex value) + public static Complex Cotangent(this Complex value) { if (value.IsReal()) { - return new Complex(HyperbolicSecant(value.Real), 0.0); + return new Complex(Cotangent(value.Real), 0d); } - var exp = value.Exponential(); - - if (exp.IsInfinity()) - { - return Complex.Zero; - } + var sinr = Sine(value.Real); + var sinhi = HyperbolicSine(value.Imaginary); + var denom = (sinr * sinr) + (sinhi * sinhi); - return 2 * exp / (exp.Square() + 1); + return new Complex(sinr * Cosine(value.Real) / denom, -sinhi * HyperbolicCosine(value.Imaginary) / denom); } /// - /// Trigonometric Hyperbolic Sine + /// Trigonometric Secant of an angle in radian /// /// - /// The angle in radian angle. + /// The angle in radian. /// /// - /// The hyperbolic sine of the radian angle. + /// The secant of the radian angle. /// - public static double HyperbolicSine(double radian) + public static double Secant(double radian) { - return (Math.Exp(radian) - Math.Exp(-radian)) / 2; + return 1 / Math.Cos(radian); } /// - /// Trigonometric Hyperbolic Sine of a Complex number. + /// Trigonometric Secant of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic sine of a complex number. + /// The secant of the complex number. /// - public static Complex HyperbolicSine(this Complex value) + public static Complex Secant(this Complex value) { if (value.IsReal()) { - return new Complex(HyperbolicSine(value.Real), 0.0); + return new Complex(Secant(value.Real), 0d); } - return new Complex( - HyperbolicSine(value.Real) * Cosine(value.Imaginary), - HyperbolicCosine(value.Real) * Sine(value.Imaginary)); + var cosr = Cosine(value.Real); + var sinhi = HyperbolicSine(value.Imaginary); + var denom = (cosr * cosr) + (sinhi * sinhi); + + return new Complex(cosr * HyperbolicCosine(value.Imaginary) / denom, Sine(value.Real) * sinhi / denom); } /// - /// Trigonometric Hyperbolic Tangent in radian + /// Trigonometric Cosecant of an angle in radian. /// /// - /// The angle in radian angle. + /// The angle in radian. /// /// - /// The hyperbolic tangent of the radian angle. + /// Cosecant of an angle in radian. /// - public static double HyperbolicTangent(double radian) + public static double Cosecant(double radian) { - if (radian > 19.1) - { - return 1.0; - } - - if (radian < -19.1) - { - return -1; - } - - var e1 = Math.Exp(radian); - var e2 = Math.Exp(-radian); - return (e1 - e2) / (e1 + e2); + return 1 / Math.Sin(radian); } /// - /// Trigonometric Hyperbolic Tangent of a Complex number. + /// Trigonometric Cosecant of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic tangent of a complex number. + /// The cosecant of a complex number. /// - public static Complex HyperbolicTangent(this Complex value) + public static Complex Cosecant(this Complex value) { if (value.IsReal()) { - return new Complex(HyperbolicTangent(value.Real), 0.0); - } - - var cosi = Cosine(value.Imaginary); - var sinhr = HyperbolicSine(value.Real); - - if (double.IsInfinity(sinhr)) - { - return new Complex(double.IsPositiveInfinity(sinhr) ? 1 : -1, 0.0); + return new Complex(Cosecant(value.Real), 0d); } - var denom = (cosi * cosi) + (sinhr * sinhr); + var sinr = Sine(value.Real); + var sinhi = HyperbolicSine(value.Imaginary); + var denom = (sinr * sinr) + (sinhi * sinhi); - return new Complex(HyperbolicCosine(value.Real) * sinhr / denom, cosi * Sine(value.Imaginary) / denom); + return new Complex(sinr * HyperbolicCosine(value.Imaginary) / denom, -Cosine(value.Real) * sinhi / denom); } /// - /// Trigonometric Arc Cosecant in radian + /// Trigonometric Arc Sine in radian /// /// /// The angle in radian angle. /// /// - /// The inverse cosecant of the radian angle. + /// The inverse sine of the radian angle. /// - /// - /// if -1 < < 1. - /// - public static double InverseCosecant(double radian) + public static double InverseSine(double radian) { - return Math.Asin(1 / radian); + return Math.Asin(radian); } /// - /// Trigonometric Arc Cosecant of this Complex number. + /// Trigonometric Arc Sine of this Complex number. /// /// /// The complex value. /// /// - /// The arc cosecant of a complex number. + /// The arc sine of a complex number. /// - public static Complex InverseCosecant(this Complex value) + public static Complex InverseSine(this Complex value) { - var inv = 1 / value; - return -Complex.ImaginaryOne * ((Complex.ImaginaryOne * inv) + (1 - inv.Square()).SquareRoot()).NaturalLogarithm(); + if (value.Imaginary > 0 || value.Imaginary == 0d && value.Real < 0) + { + return -InverseSine(-value); + } + + return -Complex.ImaginaryOne * ((1 - value.Square()).SquareRoot() + (Complex.ImaginaryOne * value)).NaturalLogarithm(); } /// @@ -539,6 +417,35 @@ namespace MathNet.Numerics return -Complex.ImaginaryOne * (value + (Complex.ImaginaryOne * (1 - value.Square()).SquareRoot())).NaturalLogarithm(); } + /// + /// Trigonometric Arc Tangent in radian + /// + /// + /// The angle in radian angle. + /// + /// + /// The inverse tangent of the radian angle. + /// + public static double InverseTangent(double radian) + { + return Math.Atan(radian); + } + + /// + /// Trigonometric Arc Tangent of this Complex number. + /// + /// + /// The complex value. + /// + /// + /// The arc tangent of a complex number. + /// + public static Complex InverseTangent(this Complex value) + { + var iz = new Complex(-value.Imaginary, value.Real); // I*this + return new Complex(0, 0.5) * ((1 - iz).NaturalLogarithm() - (1 + iz).NaturalLogarithm()); + } + /// /// Trigonometric Arc Cotangent in radian /// @@ -574,402 +481,495 @@ namespace MathNet.Numerics } /// - /// Trigonometric Hyperbolic Arc Cosecant + /// Trigonometric Arc Secant in radian /// /// /// The angle in radian angle. /// /// - /// The inverse hyperbolic cosecant of the radian angle. + /// The inverse secant of the radian angle. /// - public static double InverseHyperbolicCosecant(double radian) + public static double InverseSecant(double radian) { - return InverseHyperbolicSine(1 / radian); + return Math.Acos(1 / radian); } /// - /// Trigonometric Hyperbolic Arc Cosecant of this Complex number. + /// Trigonometric Arc Secant of this Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic arc cosecant of a complex number. + /// The arc secant of a complex number. /// - public static Complex InverseHyperbolicCosecant(this Complex value) + public static Complex InverseSecant(this Complex value) { var inv = 1 / value; - return (inv + (inv.Square() + 1).SquareRoot()).NaturalLogarithm(); + return -Complex.ImaginaryOne * (inv + (Complex.ImaginaryOne * (1 - inv.Square()).SquareRoot())).NaturalLogarithm(); } /// - /// Trigonometric Hyperbolic Area Cosine + /// Trigonometric Arc Cosecant in radian /// /// /// The angle in radian angle. /// /// - /// The inverse hyperbolic cosine of the radian angle. + /// The inverse cosecant of the radian angle. /// - public static double InverseHyperbolicCosine(double radian) + /// + /// if -1 < < 1. + /// + public static double InverseCosecant(double radian) { - return Math.Log(radian + (Math.Sqrt(radian - 1) * Math.Sqrt(radian + 1)), Math.E); + return Math.Asin(1 / radian); } /// - /// Trigonometric Hyperbolic Arc Cosine of this Complex number. + /// Trigonometric Arc Cosecant of this Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic arc cosine of a complex number. + /// The arc cosecant of a complex number. /// - public static Complex InverseHyperbolicCosine(this Complex value) + public static Complex InverseCosecant(this Complex value) { - return (value + ((value - 1).SquareRoot() * (value + 1).SquareRoot())).NaturalLogarithm(); + var inv = 1 / value; + return -Complex.ImaginaryOne * ((Complex.ImaginaryOne * inv) + (1 - inv.Square()).SquareRoot()).NaturalLogarithm(); } /// - /// Trigonometric Hyperbolic Arc Cotangent + /// Trigonometric Hyperbolic Sine /// /// /// The angle in radian angle. /// /// - /// The inverse hyperbolic cotangent of the radian angle. + /// The hyperbolic sine of the radian angle. /// - public static double InverseHyperbolicCotangent(double radian) + public static double HyperbolicSine(double radian) { - return 0.5 * Math.Log((radian + 1) / (radian - 1), Math.E); + return (Math.Exp(radian) - Math.Exp(-radian)) / 2; } /// - /// Trigonometric Hyperbolic Arc Cotangent of this Complex number. + /// Trigonometric Hyperbolic Sine of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic arc cotangent of a complex number. + /// The hyperbolic sine of a complex number. /// - public static Complex InverseHyperbolicCotangent(this Complex value) + public static Complex HyperbolicSine(this Complex value) { - var inv = 1.0 / value; - return 0.5 * ((1.0 + inv).NaturalLogarithm() - (1.0 - inv).NaturalLogarithm()); + if (value.IsReal()) + { + return new Complex(HyperbolicSine(value.Real), 0.0); + } + + return new Complex( + HyperbolicSine(value.Real) * Cosine(value.Imaginary), + HyperbolicCosine(value.Real) * Sine(value.Imaginary)); } /// - /// Trigonometric Hyperbolic Area Secant + /// Trigonometric Hyperbolic Cosine + /// + /// + /// The angle in radian. + /// + /// + /// The hyperbolic Cosine of the radian angle. + /// + public static double HyperbolicCosine(double radian) + { + return (Math.Exp(radian) + Math.Exp(-radian)) / 2; + } + + /// + /// Trigonometric Hyperbolic Cosine of a Complex number. + /// + /// + /// The complex value. + /// + /// + /// The hyperbolic cosine of a complex number. + /// + public static Complex HyperbolicCosine(this Complex value) + { + if (value.IsReal()) + { + return new Complex(HyperbolicCosine(value.Real), 0.0); + } + + return new Complex( + HyperbolicCosine(value.Real) * Cosine(value.Imaginary), + HyperbolicSine(value.Real) * Sine(value.Imaginary)); + } + + /// + /// Trigonometric Hyperbolic Tangent in radian /// /// /// The angle in radian angle. /// /// - /// The inverse hyperbolic secant of the radian angle. + /// The hyperbolic tangent of the radian angle. /// - public static double InverseHyperbolicSecant(double radian) + public static double HyperbolicTangent(double radian) { - return InverseHyperbolicCosine(1 / radian); + if (radian > 19.1) + { + return 1.0; + } + + if (radian < -19.1) + { + return -1; + } + + var e1 = Math.Exp(radian); + var e2 = Math.Exp(-radian); + return (e1 - e2) / (e1 + e2); } /// - /// Trigonometric Hyperbolic Arc Secant of this Complex number. + /// Trigonometric Hyperbolic Tangent of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic arc secant of a complex number. + /// The hyperbolic tangent of a complex number. /// - public static Complex InverseHyperbolicSecant(this Complex value) + public static Complex HyperbolicTangent(this Complex value) { - var inv = 1 / value; - return (inv + ((inv - 1).SquareRoot() * (inv + 1).SquareRoot())).NaturalLogarithm(); + if (value.IsReal()) + { + return new Complex(HyperbolicTangent(value.Real), 0.0); + } + + var cosi = Cosine(value.Imaginary); + var sinhr = HyperbolicSine(value.Real); + + if (double.IsInfinity(sinhr)) + { + return new Complex(double.IsPositiveInfinity(sinhr) ? 1 : -1, 0.0); + } + + var denom = (cosi * cosi) + (sinhr * sinhr); + + return new Complex(HyperbolicCosine(value.Real) * sinhr / denom, cosi * Sine(value.Imaginary) / denom); } /// - /// Trigonometric Hyperbolic Area Sine + /// Trigonometric Hyperbolic Cotangent /// /// /// The angle in radian angle. /// /// - /// The inverse hyperbolic sine of the radian angle. + /// The hyperbolic cotangent of the radian angle. /// - public static double InverseHyperbolicSine(double radian) + public static double HyperbolicCotangent(double radian) { - return Math.Log(radian + Math.Sqrt((radian * radian) + 1), Math.E); + if (radian > 19.115) + { + return 1.0; + } + + if (radian < -19.115) + { + return -1; + } + + var e1 = Math.Exp(radian); + var e2 = Math.Exp(-radian); + return (e1 + e2) / (e1 - e2); } /// - /// Trigonometric Hyperbolic Arc Sine of this Complex number. + /// Trigonometric Hyperbolic Cotangent of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic arc sine of a complex number. + /// The hyperbolic cotangent of a complex number. /// - public static Complex InverseHyperbolicSine(this Complex value) + public static Complex HyperbolicCotangent(this Complex value) { - return (value + (value.Square() + 1).SquareRoot()).NaturalLogarithm(); + if (value.IsReal()) + { + return new Complex(HyperbolicCotangent(value.Real), 0.0); + } + + var sini = Sine(value.Imaginary); + var sinhr = HyperbolicSine(value.Real); + + if (double.IsInfinity(sinhr)) + { + return new Complex(double.IsPositiveInfinity(sinhr) ? 1 : -1, 0.0); + } + + var denom = (sini * sini) + (sinhr * sinhr); + + return new Complex(sinhr * HyperbolicCosine(value.Real) / denom, sini * Cosine(value.Imaginary) / denom); } /// - /// Trigonometric Hyperbolic Area Tangent + /// Trigonometric Hyperbolic Secant /// /// /// The angle in radian angle. /// /// - /// The inverse hyperbolic tangent of the radian angle. + /// The hyperbolic secant of the radian angle. /// - public static double InverseHyperbolicTangent(double radian) + public static double HyperbolicSecant(double radian) { - return 0.5 * Math.Log((1 + radian) / (1 - radian), Math.E); + return 1 / HyperbolicCosine(radian); } /// - /// Trigonometric Hyperbolic Arc Tangent of this Complex number. + /// Trigonometric Hyperbolic Secant of a Complex number. /// /// /// The complex value. /// /// - /// The hyperbolic arc tangent of a complex number. + /// The hyperbolic secant of a complex number. /// - public static Complex InverseHyperbolicTangent(this Complex value) + public static Complex HyperbolicSecant(this Complex value) { - return 0.5 * ((1 + value).NaturalLogarithm() - (1 - value).NaturalLogarithm()); + if (value.IsReal()) + { + return new Complex(HyperbolicSecant(value.Real), 0.0); + } + + var exp = value.Exponential(); + + if (exp.IsInfinity()) + { + return Complex.Zero; + } + + return 2 * exp / (exp.Square() + 1); } /// - /// Trigonometric Arc Secant in radian + /// Trigonometric Hyperbolic Arc Cosecant /// /// /// The angle in radian angle. /// /// - /// The inverse secant of the radian angle. + /// The inverse hyperbolic cosecant of the radian angle. /// - public static double InverseSecant(double radian) + public static double InverseHyperbolicCosecant(double radian) { - return Math.Acos(1 / radian); + return InverseHyperbolicSine(1 / radian); } /// - /// Trigonometric Arc Secant of this Complex number. + /// Trigonometric Hyperbolic Arc Cosecant of this Complex number. /// /// /// The complex value. /// /// - /// The arc secant of a complex number. + /// The hyperbolic arc cosecant of a complex number. /// - public static Complex InverseSecant(this Complex value) + public static Complex InverseHyperbolicCosecant(this Complex value) { var inv = 1 / value; - return -Complex.ImaginaryOne * (inv + (Complex.ImaginaryOne * (1 - inv.Square()).SquareRoot())).NaturalLogarithm(); + return (inv + (inv.Square() + 1).SquareRoot()).NaturalLogarithm(); } /// - /// Trigonometric Arc Sine in radian + /// Trigonometric Hyperbolic Area Sine /// /// /// The angle in radian angle. /// /// - /// The inverse sine of the radian angle. + /// The inverse hyperbolic sine of the radian angle. /// - public static double InverseSine(double radian) + public static double InverseHyperbolicSine(double radian) { - return Math.Asin(radian); + return Math.Log(radian + Math.Sqrt((radian * radian) + 1), Math.E); } /// - /// Trigonometric Arc Sine of this Complex number. + /// Trigonometric Hyperbolic Arc Sine of this Complex number. /// /// /// The complex value. /// /// - /// The arc sine of a complex number. + /// The hyperbolic arc sine of a complex number. /// - public static Complex InverseSine(this Complex value) + public static Complex InverseHyperbolicSine(this Complex value) { - if (value.Imaginary > 0 || value.Imaginary == 0d && value.Real < 0) - { - return -InverseSine(-value); - } - - return -Complex.ImaginaryOne * ((1 - value.Square()).SquareRoot() + (Complex.ImaginaryOne * value)).NaturalLogarithm(); + return (value + (value.Square() + 1).SquareRoot()).NaturalLogarithm(); } /// - /// Trigonometric Arc Tangent in radian + /// Trigonometric Hyperbolic Area Cosine /// /// /// The angle in radian angle. /// /// - /// The inverse tangent of the radian angle. + /// The inverse hyperbolic cosine of the radian angle. /// - public static double InverseTangent(double radian) + public static double InverseHyperbolicCosine(double radian) { - return Math.Atan(radian); + return Math.Log(radian + (Math.Sqrt(radian - 1) * Math.Sqrt(radian + 1)), Math.E); } /// - /// Trigonometric Arc Tangent of this Complex number. + /// Trigonometric Hyperbolic Arc Cosine of this Complex number. /// /// /// The complex value. /// /// - /// The arc tangent of a complex number. + /// The hyperbolic arc cosine of a complex number. /// - public static Complex InverseTangent(this Complex value) + public static Complex InverseHyperbolicCosine(this Complex value) { - var iz = new Complex(-value.Imaginary, value.Real); // I*this - return new Complex(0, 0.5) * ((1 - iz).NaturalLogarithm() - (1 + iz).NaturalLogarithm()); + return (value + ((value - 1).SquareRoot() * (value + 1).SquareRoot())).NaturalLogarithm(); } /// - /// Converts a radian (2*Pi-periodic) angle to a degree (360-periodic) angle. + /// Trigonometric Hyperbolic Area Tangent /// /// - /// The radian to convert. + /// The angle in radian angle. /// /// - /// The converted degree. + /// The inverse hyperbolic tangent of the radian angle. /// - public static double RadianToDegree(double radian) + public static double InverseHyperbolicTangent(double radian) { - return radian / Constants.Degree; + return 0.5 * Math.Log((1 + radian) / (1 - radian), Math.E); } /// - /// Converts a radian (2*Pi-periodic) angle to a grad (400-periodic) angle. + /// Trigonometric Hyperbolic Arc Tangent of this Complex number. /// - /// - /// The radian to convert. + /// + /// The complex value. /// /// - /// The converted grad. + /// The hyperbolic arc tangent of a complex number. /// - public static double RadianToGrad(double radian) + public static Complex InverseHyperbolicTangent(this Complex value) { - return radian / Constants.Grad; + return 0.5 * ((1 + value).NaturalLogarithm() - (1 - value).NaturalLogarithm()); } /// - /// Trigonometric Secant of an angle in radian + /// Trigonometric Hyperbolic Arc Cotangent /// /// - /// The angle in radian. + /// The angle in radian angle. /// /// - /// The secant of the radian angle. + /// The inverse hyperbolic cotangent of the radian angle. /// - public static double Secant(double radian) + public static double InverseHyperbolicCotangent(double radian) { - return 1 / Math.Cos(radian); + return 0.5 * Math.Log((radian + 1) / (radian - 1), Math.E); } /// - /// Trigonometric Secant of a Complex number. + /// Trigonometric Hyperbolic Arc Cotangent of this Complex number. /// /// /// The complex value. /// /// - /// The secant of the complex number. + /// The hyperbolic arc cotangent of a complex number. /// - public static Complex Secant(this Complex value) + public static Complex InverseHyperbolicCotangent(this Complex value) { - if (value.IsReal()) - { - return new Complex(Secant(value.Real), 0d); - } - - var cosr = Cosine(value.Real); - var sinhi = HyperbolicSine(value.Imaginary); - var denom = (cosr * cosr) + (sinhi * sinhi); - - return new Complex(cosr * HyperbolicCosine(value.Imaginary) / denom, Sine(value.Real) * sinhi / denom); + var inv = 1.0 / value; + return 0.5 * ((1.0 + inv).NaturalLogarithm() - (1.0 - inv).NaturalLogarithm()); } /// - /// Trigonometric Sine of an angle in radian + /// Trigonometric Hyperbolic Area Secant /// /// - /// The angle in radian. + /// The angle in radian angle. /// /// - /// The sine of the radian angle. + /// The inverse hyperbolic secant of the radian angle. /// - public static double Sine(double radian) + public static double InverseHyperbolicSecant(double radian) { - return Math.Sin(radian); + return InverseHyperbolicCosine(1 / radian); } /// - /// Trigonometric Sine of a Complex number. + /// Trigonometric Hyperbolic Arc Secant of this Complex number. /// /// /// The complex value. /// /// - /// The sine of the complex number. + /// The hyperbolic arc secant of a complex number. /// - public static Complex Sine(this Complex value) + public static Complex InverseHyperbolicSecant(this Complex value) { - if (value.IsReal()) - { - return new Complex(Sine(value.Real), 0.0); - } - - return new Complex( - Sine(value.Real) * HyperbolicCosine(value.Imaginary), - Cosine(value.Real) * HyperbolicSine(value.Imaginary)); + var inv = 1 / value; + return (inv + ((inv - 1).SquareRoot() * (inv + 1).SquareRoot())).NaturalLogarithm(); } /// - /// Trigonometric Tangent of an angle in radian + /// Trigonometric Hyperbolic Cosecant /// /// /// The angle in radian. /// /// - /// The tangent of the radian angle. + /// The hyperbolic cosecant of the radian angle. /// - public static double Tangent(double radian) + public static double HyperbolicCosecant(double radian) { - return Math.Tan(radian); + return 1 / HyperbolicSine(radian); } /// - /// Trigonometric Tangent of a Complex number. + /// Trigonometric Hyperbolic Cosecant of a Complex number. /// /// /// The complex value. /// /// - /// The tangent of the complex number. + /// The hyperbolic cosecant of a complex number. /// - public static Complex Tangent(this Complex value) + public static Complex HyperbolicCosecant(this Complex value) { if (value.IsReal()) { - return new Complex(Tangent(value.Real), 0.0); + return new Complex(HyperbolicCosecant(value.Real), 0.0); } - var cosr = Cosine(value.Real); - var sinhi = HyperbolicSine(value.Imaginary); - var denom = (cosr * cosr) + (sinhi * sinhi); + var exp = value.Exponential(); - return new Complex(Sine(value.Real) * cosr / denom, sinhi * HyperbolicCosine(value.Imaginary) / denom); + if (exp.IsInfinity()) + { + return Complex.Zero; + } + + return 2 * exp / (exp.Square() - 1); } } } \ No newline at end of file