root / ase / test / distmom.py @ 1
Historique | Voir | Annoter | Télécharger (661 octet)
1 |
from ase.dft import get_distribution_moment |
---|---|
2 |
import numpy as np |
3 |
|
4 |
precision = 1E-8
|
5 |
|
6 |
x = np.linspace(-50., 50., 1000) |
7 |
y = np.exp(-x**2 / 2.) |
8 |
area, center, mom2 = get_distribution_moment(x, y, (0, 1, 2)) |
9 |
assert sum((abs(area - np.sqrt(2. * np.pi)), abs(center), abs(mom2 - 1.))) < precision |
10 |
|
11 |
x = np.linspace(-1., 1., 100000) |
12 |
for order in range(0, 9): |
13 |
y = x**order |
14 |
area = get_distribution_moment(x, y) |
15 |
assert abs(area - (1. - (-1.)**(order + 1)) / (order + 1.)) < precision |
16 |
|
17 |
x = np.linspace(-50., 50., 100) |
18 |
y = np.exp(-2. * (x - 7.)**2 / 10.) + np.exp(-2. * (x + 5.)**2 / 10.) |
19 |
center=get_distribution_moment(x, y, 1)
|
20 |
assert abs(center - 1.) < precision |