ฟังก์ชัน polar ของจำนวนเชิงซ้อนใช้ส่งคืนจำนวนเชิงซ้อน
polar() function ถูกกำหนดในไฟล์หัวข้อ complex ใน C++ มันรับขนาด (magnitude) และมุมเฟส (phase angle) ของจำนวนเชิงซ้อนและสร้างจำนวนเชิงซ้อนโดยใช้ค่าเหล่านี้
ไวยากรณ์
polar(mag, phase);
พารามิเตอร์ - รับสองค่าเป็นพารามิเตอร์ คือ phase และ magnitude ของจำนวนเชิงซ้อนที่จะสร้าง
ค่าที่ส่งคืน - ฟังก์ชันส่งคืนจำนวนเชิงซ้อน
polar(0.2, 0.5) -> (0.175517, 0.0958851)
ตัวอย่าง
#include <iostream>
#include <complex>
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)