首頁  >  文章  >  後端開發  >  C++程式以給定弧度值找到雙曲餘弦值

C++程式以給定弧度值找到雙曲餘弦值

PHPz
PHPz轉載
2023-08-31 23:25:081304瀏覽

C++程式以給定弧度值找到雙曲餘弦值

雙曲函數是使用雙曲線而不是圓定義的,與普通三角函數相當。雙曲函數在雙曲幾何中用於計算角度和距離。它們也出現在大量線性微分方程、三次方程式等的解中。對於給定的角度$\theta$。雙曲線餘弦函數 cosh$(\theta)$ 如下

$$\mathrm{cos(x)\:=\:\frac{e^x\: \:e^{-x}}{2}\:=\:\frac{e^{2x } 1}{2e^x}\:=\:\frac{1 e^{-2x}}{2e^{-x}}}$$

#在本文中,我們將討論當角度以弧度單位給出時,在 C 中取得 cosh$(\theta)$ 值的技術。

cosh() 函數

這個 cosh$(\theta)$ 運算需要 C 中 cmath 套件中的 cosh() 函數。此函數以弧度角度作為輸入,傳回雙曲餘弦結果。這裡使用簡單的語法:

文法

#include < cmath >
cosh( <angle in radian> )

演算法

  • 將角度 x(以弧度表示)作為輸入
  • 使用 cosh( x ) 計算 cosh (x)
  • 傳回結果。

範例

#include <iostream>
#include <cmath>
using namespace std;

float solve( float x ) {
   float answer;
   answer = cosh( x );
   return answer;
}

int main()
{
   cout << "The value of cosh( pi/2 ) is: " << solve( 3.14159 / 2 ) << endl;
   cout << "The value of cosh( pi ) is: " << solve( 3.14159 ) << endl;
   cout << "The value of cosh with an angle of 90 degrees is: " << solve( 90 * 3.14159 / 180 ) << endl;
   cout << "The value of cosh with an angle of 45 degrees is: " << solve( 45 * 3.14159 / 180 ) << endl;
}

輸出

The value of cosh( pi/2 ) is: 2.50918
The value of cosh( pi ) is: 11.5919
The value of cosh with an angle of 90 degrees is: 2.50918
The value of cosh with an angle of 45 degrees is: 1.32461

在此範例中,前兩個輸入值以弧度為單位,而後兩個輸入值以度為單位,已使用下列公式轉換為弧度:

$$\mathrm{\theta_{rad}\:=\:\theta_{deg}\:\times\:\frac{\pi}{180}}$$

結論

在 C 中,使用 cosh() 函數確定給定角度(以弧度為單位)的雙曲餘弦值。 cmath 頭檔必須包含在我們的 C 程式碼中才能使用此函數,即使它是標準函式庫的一部分。如果結果太大,則 cosh() 函數將錯誤代碼設為 ERANGE 並傳回值 HUGE_VAL(可以是正值或負值,取決於 x 的值)。儘管 C90 版本的 C 具有雙精確度回傳類型,但後來的 C 版本除了改進了整型的泛型(模板)用法之外,還重載了 float 和 long double 的方法。文章中使用了該函數的各種參數,以弧度或度為單位;但是,對於度數,將使用上面給出的公式將值轉換為弧度。

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

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