-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_vs_gridpoints.py
73 lines (57 loc) · 1.75 KB
/
error_vs_gridpoints.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
"""
Created on Fri Aug 10 18:44:46 2018
@author: Roland Scheidel
"""
from Na2 import Na2
import helper_functions as hf
import numpy as np
import matplotlib.pyplot as plt
from time import perf_counter
import os
a = 1
b = 13
X = Na2("X", 0)
B = Na2("B", 0)
maxV = 2
average_absolute_error = []
h = []
maxSteps = 14
# calculate FC factors analytically
FC_analytic = np.zeros([maxV, maxV])
for i in range(0, maxV):
for j in range(0, maxV):
FC_analytic[i, j] = hf.franck_condon_analytic(X, i, B, j)
# compare with numerical calculations for varying number of grid points
for counter in range(4, maxSteps):
print(counter)
N = 2 ** counter
xi = np.linspace(a, b, N)
h.append(N)
Vi_X = X.harmonic(xi)
Vi_B = B.harmonic(xi)
ev, U = hf.solve_schroedinger_tridiagonal(xi, Vi_X, Na2.M)
ev2, U2 = hf.solve_schroedinger_tridiagonal(xi, Vi_B, Na2.M)
P = U ** 2
P2 = U2 ** 2
FC_numeric = np.zeros([maxV, maxV])
t1_start = perf_counter()
for i in range(0, maxV):
for j in range(0, maxV):
s = hf.simpson(xi, U[:, i] * U2[:, j]) ** 2
FC_numeric[i, j] = s
FC_analytic[i, j] = hf.franck_condon_analytic(X, i, B, j)
t1_stop = perf_counter()
absolute_error = abs(FC_analytic - FC_numeric)
print('err')
print(absolute_error)
average_absolute_error.append(np.average(absolute_error))
plt.figure(2)
plt.plot(h, average_absolute_error, '-+')
print('max err',h, average_absolute_error)
plt.yscale('log', basey=10)
plt.xscale('log', basex=2)
plt.xlabel('Anzahl an Gridpunkten')
plt.ylabel('durchschnittlicher absoluter Fehler')
filename = os.path.join('Output', 'gridpoints_vs_error_'+str(maxSteps)+'.svg')
plt.savefig(filename, bbox_inches='tight', format='svg')
plt.show()