首頁  >  文章  >  後端開發  >  C++程式來計算給定弧度值的雙曲正弦

C++程式來計算給定弧度值的雙曲正弦

WBOY
WBOY轉載
2023-08-26 09:29:141108瀏覽

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 具有 double 返回類型。本文使用了該函數的各種參數,以弧度或度為單位;但是,對於度數,將使用上面給出的公式將值轉換為弧度。

以上是C++程式來計算給定弧度值的雙曲正弦的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除