-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek3.py
More file actions
34 lines (26 loc) · 713 Bytes
/
week3.py
File metadata and controls
34 lines (26 loc) · 713 Bytes
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
import math
import cmath
from week1 import cartesian_to_polar as cf
print(cf(-15,-8))
print(cf(math.sqrt(1/3),math.sqrt(2/3)))
#multiplying complex numbers
def cmultiply(a,b):
return a*b
print(cmultiply(2-7j,3-2j))
#magnitude of complex numbers
print(abs(complex(5,-12)))
#converting complex numbers to polar form
def cm2polar(a):
"""
converts the complex number into polar form,returns a tuple r,phi where r is
modulus, phi is phase angle
"""
return cmath.polar(a)
def polar_display(a,b):
"""
displaying the polar form of complex number a+ib in conventional form
"""
q=math.pi/b
return f"{a}e**iPI/{q}"
r,phi=cm2polar(complex(0,5))
print(polar_display(r,phi))