C++ 中複數的 polar() 函式


複數的 polar 函式用於返回複數。

polar() 函式在 c++ 的 complex 標頭檔案中定義。它獲取複數的幅度角和相位角,並使用這些值生成一個複數。

語法

polar(mag, phase);

引數 - 它接受兩個值作為引數,即要生成的複數的相位和幅度。

返回值 - 函式返回一個複數。

polar(0.2, 0.5)
-> (0.175517,0.0958851)

示例

 即時演示

#include<iostream>
#include>complex.h>
using namespace std;
int main () {
   cout<<"\t\tRUN 1\n";
   cout<<"Complex number with magnitude: 5.2 and phase angle: 1.6 is ";
   cout<<polar(5.2,1.6)<<endl;
   cout<<"\t\tRUN 2\n";
   cout<<"Complex number with magnitude: 0.5 and phase angle: 0.2 is ";
   cout<<polar(0.5,0.2)<<endl;
   cout<<"\t\tRUN 3\n";
   cout<<"Complex number with magnitude: 0.2 and phase angle: 0.5 is ";
   cout<<polar(0.2,0.5)<<endl;
   return 0;
}

輸出

RUN 1
Complex number with magnitude: 5.2 and phase angle: 1.6 is (-0.151838,5.19778)
RUN 2
Complex number with magnitude: 0.5 and phase angle: 0.2 is (0.490033,0.0993347)
RUN 3
Complex number with magnitude: 0.2 and phase angle: 0.5 is (0.175517,0.0958851)

更新於:2020-04-17

699 次瀏覽

開啟您的職業

完成課程取得認證

開始
廣告