用于 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)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP