Patched frequencies in rk3.py

This commit is contained in:
madmaurice 2016-03-17 11:55:11 +01:00
parent e9d094b95f
commit 03009f7824

15
rk3.py
View file

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import math import math
import matplotlib.pyplot as plt
def rk3(h,tn,yn,ys,param=[]): def rk3(h,tn,yn,ys,param=[]):
k1 = ys(tn,yn,*param) k1 = ys(tn,yn,*param)
@ -13,17 +14,23 @@ def main():
C = 1e-6 C = 1e-6
us = lambda tn, un, f: (U(tn,f) - un)/(R*C) us = lambda tn, un, f: (U(tn,f) - un)/(R*C)
fc = 1.0/(2*math.pi*R*C) fc = 1.0/(2*math.pi*R*C)
for f in [ 2**(i) * fc for i in range(-5,8)]: frequencies = [ 2**(i) * fc for i in range(-5,8)]
ucmax_list = []
ucmin_list = []
for f in frequencies:
print("Simulation f = %.3f Hz" % f)
ucmax = 0 ucmax = 0
ucmin = 0 ucmin = 0
tn = 0 tn = 0
un = 0 un = 0
for i in range(1000000): for i in range(int(1000*f)):
tn, un = rk3(0.000001, tn, un, us, [f]) tn, un = rk3(1/(1000*f), tn, un, us, [f])
ucmax = max(un,ucmax) ucmax = max(un,ucmax)
ucmin = min(un,ucmin) ucmin = min(un,ucmin)
ucmax_list.append(ucmax)
ucmin_list.append(ucmin)
print(" %10.3f : %10.6f %10.6f" % (f,ucmax,ucmin)) plt.plot(frequencies, ucmax_list, 'r', frequencies, ucmin_list, 'b').show()
if __name__ == '__main__': if __name__ == '__main__':