-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegrate.py
More file actions
45 lines (37 loc) · 1.24 KB
/
Copy pathintegrate.py
File metadata and controls
45 lines (37 loc) · 1.24 KB
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
import numpy as np
def integrate(lngCoeff, lngBasis, xmin, xmax, ymin, ymax, dy):
'''
Numerical integration by a trapezoidal Riemann sum.
Parameters
----------
lngCoeff :
- lngCoeff of the basis terms for the natural log of the instantaneous density of states, g
lngBasis :
- natural log of the density of states, g
ymin, ymax :
- defines the range of values that y can take
- analogous to "energy range" in multicanonical or Wang-Landau schemes
dy :
- bin width of the Riemann sum
Returns
-------
result of the integral
'''
integral = 0.0
norm = 0.0
y = ymin
while (y <= ymax-dy):
y1 = y
y2 = y + dy
norm = norm + dy*(((np.exp(np.dot(np.asarray(lngCoeff),np.asarray(lngBasis(y1))))) + (np.exp(np.dot(np.asarray(lngCoeff),np.asarray(lngBasis(y2))))))/2.0)
y = y + dy
norm = (xmax-xmin)/norm
y = ymin
while (y <= ymax-dy):
y1 = y
y2 = y + dy
I1 = (y*np.exp(np.dot(np.asarray(lngCoeff),np.asarray(lngBasis(y1)))))
I2 = ((y+dy)*np.exp(np.dot(np.asarray(lngCoeff),np.asarray(lngBasis(y2)))))
integral += dy*(I1+I2)/2.0
y = y + dy
return (integral*norm)