Newer
Older
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
import cmath
# sinus
def integrate(a, b, omega, n, epsilon):
m = (a+b)/2
h = b-a
# e^(-i*t*n*omega) faktorerna
ae = cmath.exp(-a*omega*n*1j)
me = cmath.exp(-m*omega*n*1j)
be = cmath.exp(-b*omega*n*1j)
aeh4 = cmath.exp(-(a+h/4)*omega*n*1j)
beh4 = cmath.exp(-(b-h/4)*omega*n*1j)
I1 = h/3*(cmath.sin(a)*ae+4*cmath.sin(m)*me+cmath.sin(b)*be)
I2 = h/6*(cmath.sin(a)*ae+4*cmath.sin(a+h/4)*aeh4+2*cmath.sin(m)*me+4*cmath.sin(b-h/4)*beh4+cmath.sin(b)*be)
I3 = I2+(I2-I1)/15
if abs((I3-I2)/I2) > epsilon:
I1 = integrate(a, m, omega, n, epsilon/2)
I2 = integrate(m, b, omega, n, epsilon/2)
I3 = I1 + I2
pass
return I3
filename = 'sinusKoefficenter'
# välj antal datapunkter
numDataPoints = 20;
# välj period
T = 2*cmath.pi
# väl undre och övre integration
a = 0
b = T + a
# välj tolerans och omega
epsilon = 0.1
omega = 2*cmath.pi/T
file=open(filename,'w')
for i in range(numDataPoints):
file.write(str(i)+';'+str(integrate(a, b, omega, i, epsilon))+'\n')
pass
file.close()
print('done')