-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplex.py
36 lines (35 loc) · 1.56 KB
/
Complex.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
import math
def sum(Real_P1,Img_P1,Real_P2,Img_P2):
res= (Real_P1+Real_P2,Img_P1+Img_P2)
if (res[1]==0): return res[0]
elif res[1]>0: return "{}+{}i".format(res[0],res[1])
else: return "{}{}i".format(res[0],res[1])
def res(Real_P1,Img_P1,Real_P2,Img_P2):
res= (Real_P1-Real_P2,Img_P1-Img_P2)
if (res[1]==0): return res[0]
elif res[1]>0: return "{}+{}i".format(res[0],res[1])
else: return "{}{}i".format(res[0],res[1])
def pro(Real_P1,Img_P1,Real_P2,Img_P2):
res= (Real_P1*Real_P2-Img_P1*Img_P2,Real_P1*Img_P2+Real_P2*Img_P1)
if (res[1]==0): return res[0]
elif res[1]>0: return "{}+{}i".format(res[0],res[1])
else: return "{}{}i".format(res[0],res[1])
def div(Real_P1,Img_P1,Real_P2,Img_P2):
res= (round((((Real_P1*Real_P2)+(Img_P1*Img_P2))/(Real_P2**2+Img_P2**2)),2),round((((Real_P2*Img_P1)-(Real_P1*Img_P2))/(Real_P2**2+Img_P2**2)),2))
if (res[1]==0): return res[0]
elif res[1]>0: return "{}+{}i".format(res[0],res[1])
else: return "{}{}i".format(res[0],res[1])
def mod(Real_P1,Img_P1):
res=(round(math.sqrt(Real_P1**2+Img_P1**2),2))
return res
def conj(Real_P1,Img_P1):
res=(Real_P1,(-1)*Img_P1)
if (res[1]==0): return res[0]
elif res[1]>0: return "{}+{}i".format(res[0],res[1])
else: return "{}{}i".format(res[0],res[1])
def ctop(Real_P1,Img_P1):
res=(round(math.sqrt(Real_P1**2+Img_P1**2),2),round(math.atan(Img_P1/Real_P1)*180/math.pi,2))
return "({},{}°)".format(res[0],res[1])
def fase(Real_P1,Img_P1):
res= round(math.atan(Img_P1/Real_P1)*180/math.pi,2)
return "{}°".format(res)