用於 C++ 中複數的 tanh() 函式
在本文中,我們將討論 C++ STL 中複數的 tanh() 函式的工作原理、語法和示例。
複數的 tanh() 屬於 <<complex> 標頭檔案中的函式。此函式用於查詢複數的雙曲正切。這是<cmath>標頭檔案下 tanh() 的複數版本。
什麼是 tanh?
Tanh 是雙曲正切函式。為了輕鬆定義該函式,我們可以說 tanh 等於雙曲正弦除以雙曲餘弦。
語法
complex<T> tanh(complex& num);
引數
該函式僅接受一個引數,它是複雜的 num。
返回值
它返回 num 的雙曲正切。
示例
Input: complex <double> num(0.0, 1.0); tanh(num); Output: (0, 1.55741) Input: complex <double> num(1.0, 0.0); tanh(num); Output: (0.761594, 0)
此方法可以按照以下方式進行 −
- 在 main 函式中,我們定義複數。
- 然後我們列印複數。
- 最後,我們列印複數的雙曲正切。
透過此方法,我們可以找出複數的雙曲正切。
示例
演示 tanh() 函式工作原理的 C++ 程式碼
#include<iostream.h> #include<complex.h> #include<cmath.h> using namespace std; int main( ) { / / defining complex number Complex<double> x(1,0); Cout<< “ tanh “<<x<<” =” << tanh(x)<<endl; return 0; }
輸出
如果我們執行以上程式碼,它將生成以下輸出 −
tanh(1.000000,0.000000) = (0.761594, 0.000000) tanh(0.000000,1.000000) = (0.000000, 1.557408)
廣告