-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreddit_hermite.py
89 lines (81 loc) · 3.54 KB
/
reddit_hermite.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import numpy as np
#from functools import cache
#@cache
def H(n, x):
m = 0
print(f"x: {x}")
if isinstance(x, np.ndarray):
a = np.ones(x.shape)
else:
a = 1
print(f"H({m}, x): {a}")
b = 2 * x
print(f"H({m + 1}, x): {b}")
yield a
while (m := m + 1) <= n - 1:
a, b = b, 2*x*b - 2*m*a
print(f"H({m}, x): {a}")
print(f"H({m + 1}, x): {b}")
yield a
yield b
def Htoo(n, x):
if isinstance(x, np.ndarray):
hermite_now = np.ones(x.shape)
else:
hermite_now = 1
hermite_next = 2 * x
yield hermite_now
for index in range(1, n):
hermite_now, hermite_next = (
hermite_next,
2 * x * hermite_next - 2 * index * hermite_now
)
yield hermite_now
yield hermite_next
#@cache
def Hermite(n, x):
return [h for h in H(n, x)][-1]
def psi(n, x):
return (1 / np.sqrt(2**n * np.math.factorial(n) * np.sqrt(np.pi))) * np.exp((- x**2 / 2)) * Hermite(n, x)
def main():
x = np.linspace(-10, 10, 10)
PSI30 = psi(30, x)
"""
>>> x = np.linspace(-10, 10, 10)
>>> [h for h in H(4, x)]
x: [-10. -7.77777778 -5.55555556 -3.33333333 -1.11111111
1.11111111 3.33333333 5.55555556 7.77777778 10. ]
a: [1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
b: [-20. -15.55555556 -11.11111111 -6.66666667 -2.22222222
2.22222222 6.66666667 11.11111111 15.55555556 20. ]
a: [-20. -15.55555556 -11.11111111 -6.66666667 -2.22222222
2.22222222 6.66666667 11.11111111 15.55555556 20. ]
b: [398. 239.97530864 121.45679012 42.44444444 2.9382716
2.9382716 42.44444444 121.45679012 239.97530864 398. ]
a: [398. 239.97530864 121.45679012 42.44444444 2.9382716
2.9382716 42.44444444 121.45679012 239.97530864 398. ]
b: [-7.88000000e+03 -3.67072702e+03 -1.30507545e+03 -2.56296296e+02
2.35939643e+00 -2.35939643e+00 2.56296296e+02 1.30507545e+03
3.67072702e+03 7.88000000e+03]
a: [-7.88000000e+03 -3.67072702e+03 -1.30507545e+03 -2.56296296e+02
2.35939643e+00 -2.35939643e+00 2.56296296e+02 1.30507545e+03
3.67072702e+03 7.88000000e+03]
b: [ 1.55212000e+05 5.56603463e+04 1.37720975e+04 1.45397531e+03
-2.28727328e+01 -2.28727328e+01 1.45397531e+03 1.37720975e+04
5.56603463e+04 1.55212000e+05]
a: [ 1.55212000e+05 5.56603463e+04 1.37720975e+04 1.45397531e+03
-2.28727328e+01 -2.28727328e+01 1.45397531e+03 1.37720975e+04
5.56603463e+04 1.55212000e+05]
b: [-3.04120000e+06 -8.36461793e+05 -1.42582703e+05 -7.64279835e+03
3.19531237e+01 -3.19531237e+01 7.64279835e+03 1.42582703e+05
8.36461793e+05 3.04120000e+06]
[array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]), array([-20. , -15.55555556, -11.11111111, -6.66666667,
-2.22222222, 2.22222222, 6.66666667, 11.11111111,
15.55555556, 20. ]), array([398. , 239.97530864, 121.45679012, 42.44444444,
2.9382716 , 2.9382716 , 42.44444444, 121.45679012,
239.97530864, 398. ]), array([-7.88000000e+03, -3.67072702e+03, -1.30507545e+03, -2.56296296e+02,
2.35939643e+00, -2.35939643e+00, 2.56296296e+02, 1.30507545e+03,
3.67072702e+03, 7.88000000e+03]), array([ 1.55212000e+05, 5.56603463e+04, 1.37720975e+04, 1.45397531e+03,
-2.28727328e+01, -2.28727328e+01, 1.45397531e+03, 1.37720975e+04,
5.56603463e+04, 1.55212000e+05])]
"""