我们知道tan
的倒数是Math.Atan
,那么cot的倒数呢? cot(x)
定义为
cot(x)=1/tan(x)
答案 0 :(得分:9)
见Inverse Cotangent。对于某些值,反函数为atan(1/x)
。
答案 1 :(得分:2)
余切逆转的另一种选择是Math.PI/2 - Math.Atan(x)
,它具有在x
为0
时正常工作的优势。
答案 2 :(得分:2)
对于Cotangent的逆,有两种常用的约定,例如cot(1)= cot(1-pi)。重要的是要考虑一个人希望使用的定义。
让arccot(x)匹配atan(1 / x),其值介于-pi / 2和pi / 2之间。这给出了0的不连续性(从-pi / 2跳到pi / 2)。这是Greg Hew的回答中使用的惯例。
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);
}
让arccot(x)成为一个连续函数,其值介于0和pi之间。这是Daniel Martin的回答中使用的惯例。
public static double Acot(double x)
{
return Math.PI/2 - Math.Atan(x);
}
答案 3 :(得分:0)
您可以使用 Math.Atan2 方法作为反向小结,如下所示,而不检查零值。
var value = Math.Atan2(1,cotValue);