Where's the inverse of Math.tanh in the math libraries?

前端 未结 4 412
猫巷女王i
猫巷女王i 2021-01-13 18:22

y = Math.Tanh(x) is the hyperbolic tangent of x. But I need f(y) = x. For the regular tangent there\'s Arctan, but where\'s Arctanh?

相关标签:
4条回答
  • 2021-01-13 18:53

    Why don't you implement one by yourself? You can find the equation e.g. here and tt's not that difficult:

    public static class MyMath
    {
        public static double Arctanh(double x)
        {
            if (Math.Abs(x) > 1)
                throw new ArgumentException("x");
    
            return 0.5 * Math.Log((1 + x) / (1 - x));
        }
    }
    
    0 讨论(0)
  • 2021-01-13 18:55

    I don't think the C# libraries include the arc hyperbolic trig functions, but they're easy to compute:

    atanh(x) = (log(1+x) - log(1-x))/2
    

    In C#:

    public static double ATanh(double x)
    {
        return (Math.Log(1 + x) - Math.Log(1 - x))/2;
    }
    
    0 讨论(0)
  • 2021-01-13 19:08

    the Inverse HTangent is can be calc by doing Log((1 + X) / (1 – X)) / 2

    0 讨论(0)
  • 2021-01-13 19:11

    I installed MathNet from the package manager. It has MathNet.Numerics.Trig.InverseHyperbolicTangent(x) which works well enough.

    0 讨论(0)
提交回复
热议问题