
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Complex Number to Polar Coordinate Values in Python
Suppose we have a complex number c, we have to convert it into polar coordinate (radius, angle). Complex number will be in form x + yj. The radius is the magnitude of the complex number which is square root of (x^2 + y^2). And the angle is the counter clockwise angle measured from positive x-axis to the line segment that joins x + yj to the origin. From the cmath library we can use the phase() function to calculate the angle. And abs() function on complex number will return the magnitude value.
So, if the input is like c = 2+5j, then the output will be (5.385164807134504, 1.1902899496825317)
To solve this, we will follow these steps −
return a pair with (|c| , phase(c) from cmath library)
Example
Let us see the following implementation to get better understanding
import cmath def solve(c): return (abs(c), cmath.phase(c)) c = 2+5j print(solve(c))
Input
2+5j
Output
(5.385164807134504, 1.1902899496825317)