C++程序,用于查找给定弧度值的双曲正弦
普通的三角函数有类似的双曲函数,这些函数是使用双曲线而不是圆定义的。在双曲几何中,双曲函数用于计算角度和距离。此外,它们出现在许多线性微分方程、三次方程等的答案中。对于给定的角度$\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() 函数
要计算 sinh$(\theta)$,将使用来自 cmath 包的 sinh() 函数。此函数通过将以弧度为单位的角度作为输入来返回双曲正弦的结果。这里使用了简单的语法
语法
#include < cmath > sinh( <angle in radian> )
算法
- 以弧度为单位输入角度 x。
- 使用 sinh( x ) 计算 sinh (x)。
- 返回结果。
示例
#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++ 具有双精度返回类型。本文使用此函数的各种参数,以弧度或度为单位;但是,对于度数,使用上面给出的公式将其转换为弧度。
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP