{"id":25435,"date":"2021-11-11T14:59:47","date_gmt":"2021-11-11T09:29:47","guid":{"rendered":"https:\/\/python-programs.com\/?p=25435"},"modified":"2021-11-14T15:02:35","modified_gmt":"2021-11-14T09:32:35","slug":"python-cmath-polar-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-cmath-polar-method-with-examples\/","title":{"rendered":"Python cmath.polar() Method with Examples"},"content":{"rendered":"
cmath.polar() Method in Python:<\/strong><\/p>\n A complex number is converted to polar coordinates using the cmath.polar() method. It returns a tuple consisting of modulus and phase.<\/p>\n A complex number in polar coordinates is defined by modulus r and phase angle phi.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n x:<\/strong> This is Required. A number used to calculate the polar coordinates of<\/p>\n Return Value:<\/strong><\/p>\n Returns a tuple value containing polar coordinates.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Note:<\/strong> The above input format is for dynamic input.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Similarly, try for the other examples<\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n cmath.polar() Method in Python: A complex number is converted to polar coordinates using the cmath.polar() method. It returns a tuple consisting of modulus and phase. A complex number in polar coordinates is defined by modulus r and phase angle phi. Syntax: cmath.polar(x) Parameters x: This is Required. A number used to calculate the polar coordinates …<\/p>\ncmath.polar(x)<\/pre>\n
Given Complex Number = 3+4j<\/pre>\n
The polar coordinates of given complex number (3+4j) = \r\n(5.0, 0.9272952180016122)<\/pre>\n
Given realpart = 5\r\nGiven imaginary part = 2<\/pre>\n
The polar coordinates of given complex number (5+2j) = \r\n(5.385164807134504, 0.3805063771123649)<\/pre>\n
cmath.polar() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import cmath module(for complex number operations) using the import keyword.\r\nimport cmath\r\n# Give the complex number as static input and store it in a variable.\r\ncomplexnumb = 3+4j\r\n# Pass the given complex number as an argument to the cmath.polar() method\r\n# that converts the given complex number to polar coordinates and returns a\r\n# tuple consisting of modulus and phase.\r\n# Store it in another variable.\r\nrslt = cmath.polar(complexnumb)\r\n# Print the result tuple consisting of modulus and phase.\r\nprint(\"The polar coordinates of given complex number\", complexnumb,\r\n \" = \")\r\nprint(rslt)\r\n<\/pre>\n
The polar coordinates of given complex number (3+4j) = \r\n(5.0, 0.9272952180016122)<\/pre>\n
import cmath\r\ncomplexnumb = -1-2j\r\nrslt = cmath.polar(complexnumb)\r\nprint(\"The polar coordinates of given complex number\", complexnumb,\r\n \" = \")\r\nprint(rslt)\r\n<\/pre>\n
The polar coordinates of given complex number (-1-2j) = \r\n(2.23606797749979, -2.0344439357957027)<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import cmath module(for complex number operations) using the import keyword.\r\nimport cmath\r\n# Give the real part and imaginary part of the complex number as user input\r\n# using map(), int(), split().\r\n# Store it in two variables.\r\nrealnumb, imaginarynumb = map(int, input(\r\n 'Enter real part and complex part of the complex number = ').split())\r\n# Using a complex() function convert those two variables into a complex number.\r\ncomplexnumb = complex(realnumb, imaginarynumb)\r\n\r\n# Pass the given complex number as an argument to the cmath.polar() method\r\n# that converts the given complex number to polar coordinates and returns a\r\n# tuple consisting of modulus and phase.\r\n# Store it in another variable.\r\nrslt = cmath.polar(complexnumb)\r\n# Print the above result tuple consisting of modulus and phase.\r\nprint(\"The polar coordinates of given complex number\", complexnumb,\r\n \" = \")\r\nprint(rslt)\r\n<\/pre>\n
Enter real part and complex part of the complex number = 5 2\r\nThe polar coordinates of given complex number (5+2j) = \r\n(5.385164807134504, 0.3805063771123649)<\/pre>\n","protected":false},"excerpt":{"rendered":"