普通三角函数类似于双曲函数,它们是使用双曲线而不是圆来定义的。在双曲几何中,双曲函数用于计算角度和距离。此外,它们还出现在许多线性微分方程、三次方程等的答案中。对于给定的角度$\theta$。双曲正弦函数 sinh$(\theta)$ 如下所示。
$$\mathrm{sinh(x)\:=\:\frac{e^x\:-\:e^{-x}}{2}\:=\:\frac{e^{2x }-1}{2e^x}\:=\:\frac{1-e^{-2x}}{2e^{-x}}}$$
在本文中,我们将讨论当角度以弧度单位给出时,在 C++ 中获取 sinh$(\theta)$ 值的技术。
要计算sinh$(\theta)$,将使用cmath包中的sinh()函数。该函数通过将弧度角作为输入,返回双曲正弦的结果。在这里,使用简单的语法:
立即学习“C++免费学习笔记(深入)”;
#include < cmath > sinh( <angle in radian> )
#include <iostream> #include <cmath> using namespace std; float solve( float x ) { float answer; answer = sinh( x ); return answer; } int main() { cout << "The value of sinh( pi/2 ) is: " << solve( 3.14159 / 2 ) << endl; cout << "The value of sinh( pi ) is: " << solve( 3.14159 ) << endl; cout << "The value of sinh with an angle of 90 degrees is: " << solve( 90 * 3.14159 / 180 ) << endl; cout <<"The value of sinh with an angle of 45 degrees is: " << solve( 45 * 3.14159 / 180 ) << endl; }
The value of sinh( pi/2 ) is: 2.3013 The value of sinh( pi ) is: 11.5487 The value of sinh with an angle of 90 degrees is: 2.3013 The value of sinh with an angle of 45 degrees is: 0.86867
此示例中的前两个输入值以弧度为单位,而后两个输入值以度为单位,已使用以下公式转换为弧度 -
$$\mathrm{\theta_{rad}\:=\:\theta_{deg}\:\times\:\frac{\pi}{180}}$$
要在 C++ 中查找给定角度的双曲正弦值(以弧度为单位),请使用 sinh() 函数。尽管此函数是标准库的一部分,但我们的 C++ 代码需要包含 cmath 头文件才能使用它。如果结果太大,则 sinh() 函数返回值 HUGE_VAL(正或负,具体取决于 x 的值)并将错误号设置为 ERANGE。 C++ 的更高版本提供了 float 和 long double 的重载方法,以及整数类型的增强型泛型(模板)用法,但 C90 版本的 C++ 具有 double 返回类型。本文使用了该函数的各种参数,以弧度或度为单位;但是,对于度数,将使用上面给出的公式将值转换为弧度。
以上就是C++程序来计算给定弧度值的双曲正弦的详细内容,更多请关注php中文网其它相关文章!
c++怎么学习?c++怎么入门?c++在哪学?c++怎么学才快?不用担心,这里为大家提供了c++速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号