-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
59 lines (49 loc) · 1.64 KB
/
app.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
from math import *
import matplotlib.pyplot as plt
from time import sleep
y_axis = []
x_axis = []
try:
print('Welcome to the Frequency response graph plotter.')
print('You can calculate and plot the value of the value of magnitude and phase')
sleep(2)
while True:
choice = input('Would you like to plot for Magnitude (Press A) or Plot for Phase (Press B): ').lower()
print(choice)
if choice == 'a' or choice == 'b':
break
else:
print('Please enter a Valid Choice: A or B')
continue
break
E = float(input('Please enter the value of E: '))
a = float(input('Please enter the (minimum value) for the range of U: '))*10
b = float(input('Please enter the (maximum value) for the range of U: '))*10
def calculate_m(E, U):
x = pow((1 - U*U),2) + pow(2*E*U, 2)
m = 1/sqrt(x)
return m
def calculate_phi(E, U):
x = 2*E*U
y = 1 - (U**2)
if y == 0: x = 0
phi = -tanh(x)
return phi
for i in range(0, 22, 2):
u = float(i/10)
x_axis.append(u)
if choice == 'a':
m = calculate_m(E, u)
y_axis.append(m)
else:
phi = calculate_phi(E, u)
y_axis.append(phi)
print(x_axis)
print(y_axis)
plt.plot(x_axis, y_axis)
plt.title('Frequency response graph')
plt.ylabel('Magnitude/Phase of resonant frequency: y-axis')
plt.xlabel('Normalised driving signal frequency: x-axis')
plt.show()
except ValueError:
print('There is an error in your inputs, Please run this program again!')