在複數頭文件中定義了用於複數的pow()函數。該函數是pow()函數的複雜版本。此函數用於計算基數x的複數冪到y-th冪。
用法:
template<class T> complex<T> pow (const complex<T>& x, int y);
or,
template<class T> complex<T> pow (const complex<T>& x, const complex<T>& y);or,
template<class T> complex<T> pow (const complex<T>& x, const T& y);or,
template<class T> complex<T> pow (const T& x, const complex<T>& y);
參數:此方法接受兩個參數:
- x:它代表複雜值的基礎。
 - y:它表示 index 為複數值。
 
返回值:此函數將基數x的複數冪返回到y-th冪。
以下示例程序旨在說明C++中的pow()函數:
示例1:
// c++ program to demonstrate 
// example of pow() function. 
  
#include <bits/stdc++.h> 
using namespace std; 
  
// driver program 
int main() 
{ 
    // initializing the complex:(1.0+2.0i) 
    complex<double> complexnumber(1.0, 2.0); 
  
    // use of pow() function for complex number 
    cout << "(1.0, 2.0)^2 = "
         << pow(complexnumber, 2) 
         << endl; 
  
    return 0; 
}
輸出:
(1.0, 2.0)^2 = (-3,4)
示例2:
// c++ program to demonstrate 
// example of pow() function. 
  
#include <bits/stdc++.h> 
using namespace std; 
  
// driver program 
int main() 
{ 
    // initializing the complex:(2.0+1.0i) 
    complex<double> complexnumber(2.0, 1.0); 
  
    // use of pow() function for complex number 
    cout << "(2.0, 1.0)^3 = "
         << pow(complexnumber, 3) 
         << endl; 
  
    return 0; 
}
輸出:
(2.0, 1.0)^3 = (2,11)
相關用法
- C++ complex exp()用法及代碼示例
 - C++ complex cos()用法及代碼示例
 - C++ complex log()用法及代碼示例
 - C++ complex tan()用法及代碼示例
 - C++ complex arg()用法及代碼示例
 - C++ complex acosh()用法及代碼示例
 - C++ complex cosh()用法及代碼示例
 - C++ complex acos()用法及代碼示例
 - C++ complex sqrt()用法及代碼示例
 - C++ complex tanh()用法及代碼示例
 - C++ complex atanh()用法及代碼示例
 - C++ complex asin()用法及代碼示例
 - C++ complex sinh()用法及代碼示例
 - C++ complex atan()用法及代碼示例
 - C++ complex polar()用法及代碼示例
 
注:本文由純淨天空篩選整理自bansal_rtk_大神的英文原創作品 pow() function for complex number in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
