在 C# 中实现三角反函数

发布于 2024-08-16 20:37:40 字数 477 浏览 4 评论 0原文

我正在尝试在 C# 应用程序中实现反三角函数。显然我不是在谈论简单的反正弦、余弦和正切,因为它们都是由 Math 类提供的。我正在寻找的是 sec、cosec 和 cotan 的倒数:

Func<double,double> secant = (d => (1 / Math.Cos(d)));
Func<double,double> cosecant = (d => (1 / Math.Sin(d)));
Func<double,double> cotangent = (d => (Math.Cos(d) / Math.Sin(d)));

现在我的问题是我想实现其中每一个的倒数,但我似乎找不到适当的倒数的简单定义 - arcsec、arccsc和 arccot - 我可以将其转换为 C# 代码。

所以我的问题是,您可以 (a) 为我指出一个好的资源的方向,还是 (b) 向我展示一些示例代码?

I'm trying to implement inverse trigonometric functions in a C# application. Obviously I'm not talking about simple inverse sin, cos and tan seeing as those are all provided by the Math class. What I'm looking for is the inverses for sec, cosec and cotan:

Func<double,double> secant = (d => (1 / Math.Cos(d)));
Func<double,double> cosecant = (d => (1 / Math.Sin(d)));
Func<double,double> cotangent = (d => (Math.Cos(d) / Math.Sin(d)));

Now my problem is that I want to implement the inverses of each of these but I can't seem to find a simple definition of the appropriate inverses - arcsec, arccsc and arccot - which I can turn into C# code.

So my question is can you either (a) point me in the direction of a good resource or (b) show me some example code for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〆凄凉。 2024-08-23 20:37:40

你肯定在开玩笑:

asec(x) = acos(1 / x)
acsc(x) = asin(1 / x)
acot(x) = atan(1 / x)

:-P

Surely you jest:

asec(x) = acos(1 / x)
acsc(x) = asin(1 / x)
acot(x) = atan(1 / x)

:-P

↘人皮目录ツ 2024-08-23 20:37:40

对于反余切,使用 atan(1 / x) 并不总是有效。例如,我需要做一个相当复杂的方程:

y = 0.25 * arccot((2.5x / 100000) - 2.1) + 0.26

当实现 atan(1 / x) 解决方案时,当 (2.5x / 100000) - 2.1 为零,并且该点左侧的所有值均低于正确值 pi / 4。

相反,使用这样的实现可以为所需的所有点提供准确的答案:

y = 0.25 * ((pi / 2) - atan((2.5x / 100000) -2.1) + 0.26

我建议访问 desmos.com/calculator 或其他一些图形实用程序并绘制实际的 arccot 函数,然后比较各种实现以确保您得到什么你想要所有的价值观。

For inverse cotangent, using atan(1 / x) will not always work. For example, I needed to do a fairly complicated equation:

y = 0.25 * arccot((2.5x / 100000) - 2.1) + 0.26

When implementing the atan(1 / x) solution, it results in a break when (2.5x / 100000) - 2.1 is zero, and all the values to the left of that point are below the correct values by pi / 4.

Instead, using an implementation as such provides the exact answers for all points needed:

y = 0.25 * ((pi / 2) - atan((2.5x / 100000) -2.1) + 0.26

I would suggest going to desmos.com/calculator or some other graphing utility and graphing the actual arccot function, then comparing various implementations to make sure you are getting what you want for all values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文