-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfasores.py
166 lines (128 loc) · 4.26 KB
/
fasores.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import numpy as np
def fasor_to_scalar(mode, x=0, y=0):
if(mode == 3):
real = x * np.cos(y*np.pi/180)
imag = x * np.sin(y*np.pi/180)
return(f"{real} + j {imag}")
print("x∠y\n")
x = float(input("x = "))
y = float(input("y = "))
real = x * np.cos(y*np.pi/180)
imag = x * np.sin(y*np.pi/180)
if(mode == 1):
print(f"{real} + j {imag}")
if(mode == 2):
return complex(real, imag)
def scalar_to_fasor(mode, x=0, y=0):
if(mode == 3):
mod = np.sqrt(x**2 + y**2)
ang = np.arctan(y/x) * 180/np.pi
return f"{mod} ∠ {ang}°"
print("x + j * y\n")
x = float(input("x = "))
y = float(input("y = "))
mod = np.sqrt(x**2 + y**2)
ang = np.arctan(y/x) * 180/np.pi
if(mode == 1):
print(f"{mod} ∠ {ang}°")
if(mode == 2):
return [mod, ang]
def complex_sum():
num_type = int(input("Tipo do num1:\n[1]fasor\n[2]complex\n>> "))
if(num_type == 1):
num1 = fasor_to_scalar(mode=2)
elif(num_type == 2):
print("x + j * y\n")
x = float(input("x = "))
y = float(input("y = "))
num1 = complex(x, y)
num_type = int(input("Tipo do num2:\n[1]fasor\n[2]complex\n>> "))
if(num_type == 1):
num2 = fasor_to_scalar(mode=2)
elif(num_type == 2):
print("aaaaaaaaaaa\nx + j * y\n")
x = float(input("x = "))
y = float(input("y = "))
num2 = complex(x, y)
result = num1 + num2
print(
f"Forma complexa: {result.real} + j {result.imag}\nForma fasorial: {scalar_to_fasor(mode=3,x=result.real, y=result.imag)}")
def complex_sub():
num_type = int(input("Tipo do num1:\n[1]fasor\n[2]complex\n>> "))
if(num_type == 1):
num1 = fasor_to_scalar(mode=2)
elif(num_type == 2):
print("x + j * y\n")
x = float(input("x = "))
y = float(input("y = "))
num1 = complex(x, y)
num_type = int(input("Tipo do num2:\n[1]fasor\n[2]complex\n>> "))
if(num_type == 1):
num2 = fasor_to_scalar(mode=2)
elif(num_type == 2):
print("aaaaaaaaaaa\nx + j * y\n")
x = float(input("x = "))
y = float(input("y = "))
num2 = complex(x, y)
sub = num1 - num2
print(
f"Forma complexa: {sub.real} + j {sub.imag}\nForma fasorial: {scalar_to_fasor(mode=3,x=sub.real, y=sub.imag)}")
def complex_mult():
num_type = int(input("Tipo do num1:\n[1]fasor\n[2]complex\n>> "))
if(num_type == 1):
print("x∠y\n")
x = float(input("x = "))
y = float(input("y = "))
num1 = [x, y]
elif(num_type == 2):
num1 = scalar_to_fasor(mode=2)
num_type = int(input("Tipo do num2:\n[1]fasor\n[2]complex\n>> "))
if(num_type == 1):
print("x∠y\n")
x = float(input("x = "))
y = float(input("y = "))
num2 = [x, y]
elif(num_type == 2):
num2 = scalar_to_fasor(mode=2)
res_mod = num1[0] * num2[0]
res_ang = num1[1] + num2[1]
print(
f"Forma complexa: {fasor_to_scalar(mode=3, x=res_mod, y=res_ang)}\nForma fasorial: {res_mod} ∠ {res_ang}°")
def complex_div():
num_type = int(input("Tipo do num1:\n[1]fasor\n[2]complex\n>> "))
if(num_type == 1):
print("x∠y\n")
x = float(input("x = "))
y = float(input("y = "))
num1 = [x, y]
elif(num_type == 2):
num1 = scalar_to_fasor(mode=2)
num_type = int(input("Tipo do num2:\n[1]fasor\n[2]complex\n>> "))
if(num_type == 1):
print("x∠y\n")
x = float(input("x = "))
y = float(input("y = "))
num2 = [x, y]
elif(num_type == 2):
num2 = scalar_to_fasor(mode=2)
res_mod = num1[0] / num2[0]
res_ang = num1[1] - num2[1]
print(
f"Forma complexa: {fasor_to_scalar(mode=3, x=res_mod, y=res_ang)}\nForma fasorial: {res_mod} ∠ {res_ang}°")
while True:
op = int(input(
"Tipo de operação:\n[1]fasor -> escalar\n[2]escalar -> fasor\n[3]Soma\n[4]Subtração\n[5]Multiplicação\n[6]Divisão\n>> "))
if(op > 0 or op < 7 and type(op) == int):
break
if op == 1:
fasor_to_scalar(mode=1)
elif op == 2:
scalar_to_fasor(mode=1)
elif op == 3:
complex_sum()
elif op == 4:
complex_sub()
elif op == 5:
complex_mult()
elif op == 6:
complex_div()