from mpmath import *
mp.dps = 60

# Read eigenvalues into a list of real numbers (mpf)
with open('eigenvalues') as f:
	eigenvalues_ = f.read().splitlines()

# How many eigenvalues to take? (max = len(eigenvalues_))
maxn_eigen = len(eigenvalues_)

# Fill in the array to use with computations
# Uncomment below to round the numbers to desired precision
eigenvalues = []
for i in range(0, maxn_eigen):
#	eigenvalues.append(floor(mp.mpf(eigenvalues_[i]) * 100000.0) / 100000.0)
	eigenvalues.append(mp.mpf(eigenvalues_[i]))

# Set temporary values for variables (in future change this to user input)
# Start value for X
X = mp.mpf(4)
# Max value for X
max_X = mp.mpf(100)
# Interval between samples
interval = mp.mpf(0.01)

steps = floor((max_X - X)/interval)
logX = ln(X)

# Now create a list with the proper values cos( t_j * log X)
values1 = []
values2 = []
xcoords = []

# the normalization to use:
normalization = mp.mpf(eigenvalues_[maxn_eigen - 1]) #This gives T

for i in range(0, int(steps)): # Fixes X
	print("Step " + str(i) + " / " + str(steps))
	logX = ln(mp.mpf(X + mp.mpf(i) * interval))
	tempsum = mp.mpc(0,0)
	for j in range(0, maxn_eigen): # Computes the sum of values at that X
		tempsum += mp.mpc(cos(eigenvalues[j] * logX), sin(eigenvalues[j] * logX))
	values1.append(mp.mpf(2) * tempsum.real / normalization)
        values2.append(mp.mpf(2) * tempsum.imag / normalization)
	xcoords.append(X + i * interval)

# Plotting
import matplotlib.pyplot as plt
plt.figure(1)
plt.plot(xcoords,values1)
plt.plot(xcoords,values2)
#plt.show()
plt.savefig('xplot.pdf', format='pdf', transparent=True)
plt.close()
