C#中的反向婴儿床

时间:2010-05-06 07:24:32

标签: c# math

我们知道tan的倒数是Math.Atan,那么cot的倒数呢? cot(x)定义为

cot(x)=1/tan(x)

4 个答案:

答案 0 :(得分:9)

Inverse Cotangent。对于某些值,反函数为atan(1/x)

答案 1 :(得分:2)

余切逆转的另一种选择是Math.PI/2 - Math.Atan(x),它具有在x0时正常工作的优势。

答案 2 :(得分:2)

对于Cotangent的逆,有两种常用的约定,例如cot(1)= cot(1-pi)。重要的是要考虑一个人希望使用的定义。

  1. 让arccot(x)匹配atan(1 / x),其值介于-pi / 2和pi / 2之间。这给出了0的不连续性(从-pi / 2跳到pi / 2)。这是Greg Hew的回答中使用的惯例。

    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);
    }
    

    public static double Acot(double x)
    {
        return x == 0 ? 0 : Math.Atan(1/x);
    }
    
  2. 让arccot(x)成为一个连续函数,其值介于0和pi之间。这是Daniel Martin的回答中使用的惯例。

    arccot with values between 0 and pi, image from Wikipedia

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

答案 3 :(得分:0)

您可以使用 Math.Atan2 方法作为反向小结,如下所示,而不检查零值。

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