-
-
Save ayosec/4712858 to your computer and use it in GitHub Desktop.
Gaussian-like distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def g(n, center, amplitude, total, density) | |
Math.sinh(density*((n.to_f - total / 2.0))/(total/2.0))/Math.sinh(density) * amplitude + center | |
end | |
N = 30 | |
Density = 10 | |
prev_value = nil | |
(0..N).each do |n| | |
value = g(n, 35, 10, N, Density) | |
print "%3d %.4f" % [n, value] | |
print " [%+.4f]" % (value - prev_value) if prev_value | |
prev_value = value | |
puts | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 25.0000 | |
1 25.6747 [+0.6747] | |
2 26.3477 [+0.6730] | |
3 27.0191 [+0.6715] | |
4 27.6892 [+0.6700] | |
5 28.3579 [+0.6687] | |
6 29.0255 [+0.6676] | |
7 29.6920 [+0.6665] | |
8 30.3576 [+0.6656] | |
9 31.0223 [+0.6647] | |
10 31.6863 [+0.6640] | |
11 32.3498 [+0.6634] | |
12 33.0127 [+0.6630] | |
13 33.6754 [+0.6626] | |
14 34.3377 [+0.6624] | |
15 35.0000 [+0.6623] | |
16 35.6623 [+0.6623] | |
17 36.3246 [+0.6624] | |
18 36.9873 [+0.6626] | |
19 37.6502 [+0.6630] | |
20 38.3137 [+0.6634] | |
21 38.9777 [+0.6640] | |
22 39.6424 [+0.6647] | |
23 40.3080 [+0.6656] | |
24 40.9745 [+0.6665] | |
25 41.6421 [+0.6676] | |
26 42.3108 [+0.6687] | |
27 42.9809 [+0.6700] | |
28 43.6523 [+0.6715] | |
29 44.3253 [+0.6730] | |
30 45.0000 [+0.6747] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby gaussian-like.rb | |
0 25.0000 | |
1 25.8538 [+0.8538] | |
2 26.6669 [+0.8131] | |
3 27.4429 [+0.7761] | |
4 28.1854 [+0.7425] | |
5 28.8976 [+0.7122] | |
6 29.5826 [+0.6850] | |
7 30.2435 [+0.6609] | |
8 30.8833 [+0.6398] | |
9 31.5048 [+0.6215] | |
10 32.1108 [+0.6060] | |
11 32.7039 [+0.5931] | |
12 33.2868 [+0.5829] | |
13 33.8621 [+0.5753] | |
14 34.4323 [+0.5702] | |
15 35.0000 [+0.5677] | |
16 35.5677 [+0.5677] | |
17 36.1379 [+0.5702] | |
18 36.7132 [+0.5753] | |
19 37.2961 [+0.5829] | |
20 37.8892 [+0.5931] | |
21 38.4952 [+0.6060] | |
22 39.1167 [+0.6215] | |
23 39.7565 [+0.6398] | |
24 40.4174 [+0.6609] | |
25 41.1024 [+0.6850] | |
26 41.8146 [+0.7122] | |
27 42.5571 [+0.7425] | |
28 43.3331 [+0.7761] | |
29 44.1462 [+0.8131] | |
30 45.0000 [+0.8538] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 25.0000 | |
1 27.8350 [+2.8350] | |
2 29.8665 [+2.0315] | |
3 31.3223 [+1.4558] | |
4 32.3656 [+1.0434] | |
5 33.1136 [+0.7479] | |
6 33.6499 [+0.5364] | |
7 34.0349 [+0.3850] | |
8 34.3117 [+0.2767] | |
9 34.5112 [+0.1996] | |
10 34.6560 [+0.1447] | |
11 34.7621 [+0.1062] | |
12 34.8416 [+0.0795] | |
13 34.9034 [+0.0617] | |
14 34.9542 [+0.0509] | |
15 35.0000 [+0.0458] | |
16 35.0458 [+0.0458] | |
17 35.0966 [+0.0509] | |
18 35.1584 [+0.0617] | |
19 35.2379 [+0.0795] | |
20 35.3440 [+0.1062] | |
21 35.4888 [+0.1447] | |
22 35.6883 [+0.1996] | |
23 35.9651 [+0.2767] | |
24 36.3501 [+0.3850] | |
25 36.8864 [+0.5364] | |
26 37.6344 [+0.7479] | |
27 38.6777 [+1.0434] | |
28 40.1335 [+1.4558] | |
29 42.1650 [+2.0315] | |
30 45.0000 [+2.8350] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment