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