C#中的反余切

5
我们知道tan的反函数是Math.Atan,那么cot的反函数呢?cot(x)的定义如下:
cot(x)=1/tan(x)
4个回答

9

3

在Cotangent的反函数中有两种常用的约定,例如cot(1)= cot(1-pi)。重要的是要仔细思考要使用哪个定义。

  1. Let arccot(x) match atan(1/x), with values between -pi/2 and pi/2. This gives a discontinuity at 0 (jumps from -pi/2 to pi/2). This is the convention used in Greg Hew's answer.

    arccot with values between -pi/2 and pi/2, image from Wolfram MathWorld

    public static double Acot(double x)
    {
        return (x < 0 ? -Math.PI/2 : Math.PI/2) - Math.Atan(x);
    }
    

    or

    public static double Acot(double x)
    {
        return x == 0 ? 0 : Math.Atan(1/x);
    }
    
  2. Let arccot(x) be a continuous function with values between 0 and pi. This is the convention used in Daniel Martin's answer.

    arccot with values between 0 and pi, image from Wikipedia

    public static double Acot(double x)
    {
        return Math.PI/2 - Math.Atan(x);
    }
    

2

求余切反函数的另一种解法是Math.PI/2 - Math.Atan(x),其优点在于当x0时可以正确工作。


0

您可以使用Math.Atan2方法作为反余切函数,无需检查零值,如下所示。

var value = Math.Atan2(1,cotValue);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接