-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathmath_polar_cord.py
60 lines (40 loc) · 1.37 KB
/
math_polar_cord.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Problem Statement
Polar coordinates are an alternative way of representing Cartesian coordinates or Complex Numbers.
A complex number z Capture.PNG
z=x+yj
is completely determined by its real part x and imaginary part y.
j is the imaginary unit.
A polar coordinate (r,φ) Capture.PNG
is completely determined by modulus r and phase angle φ.
If we convert complex number z to its polar coordinate, we find,
r : Distance from z to origin, i.e., x2+y2‾‾‾‾‾‾‾√
φ : Counter clockwise angle measured from the positive x-axis to the line segment that joins z to origin.
Python's cmath module provides acces to mathematical functions for complex numbers.
cmath.phase
Return phase of complex number z (also known as argument of z).
>>> phase(complex(-1.0, 0.0))
3.1415926535897931
abs
Return modulus (absolute value) of complex number z.
>>> abs(complex(-1.0, 0.0))
1.0
Task
You are given a complex z. Your task is to convert it to polar coordinate.
Input Format
Single line containing complex number z.
Output Format
Two lines:
First line contains, value of r.
Second line contains, value of φ.
Sample Input
1+2j
Sample Output
2.23606797749979
1.1071487177940904
Note : Output should be correct up to 3 decimal places.
"""
from cmath import sqrt,phase
c = complex(input())
print sqrt(pow(c.real,2)+pow(c.imag,2)).real
print phase(complex(c.real,c.imag))