ruby-mext 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mext/math.rb +1 -0
- data/lib/mext/math/log.rb +91 -0
- data/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9b83368400b233efcb67e07aa764cb5d2e94b0b1b5e9b4ff2a920a2792a79ff
|
4
|
+
data.tar.gz: 42d1153c6aefcc11f0df912d83217664389330b727c290615ce876e7f94a063b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c39bfe3de9837b0373507e98dcce6998c04b13e1bc6c25b106ca6fba1497208e0585c8785bc453e772ce6e8bbfc4bb2cdca4a5da85eb49233692bd53e801595
|
7
|
+
data.tar.gz: 6c0fb5664761bd1298a69d7f7a2b9c8893b1035bb72824d2f42c891c137272dc56fefa2c2f3261861a81bf98b2cb30e231c312e41cf4685b0a6ad11986ddc043
|
data/lib/mext/math.rb
CHANGED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'cmath'
|
2
|
+
|
3
|
+
module Math
|
4
|
+
|
5
|
+
class Log < Function
|
6
|
+
|
7
|
+
attr_reader :y_start, :y_end, :base
|
8
|
+
attr_reader :a, :b, :c
|
9
|
+
|
10
|
+
#
|
11
|
+
# +DEFAULT_BASE+: default logarithmic curvature factor for +Log()+
|
12
|
+
#
|
13
|
+
DEFAULT_BASE = Math::E
|
14
|
+
|
15
|
+
#
|
16
|
+
# +Math::Log.new(ystart, yend, xstart, xend, base = DEFAULT_BASE)+:
|
17
|
+
#
|
18
|
+
# exponential curve `y = e^(a*x + b) + c` where:
|
19
|
+
#
|
20
|
+
# `c = yend + base`
|
21
|
+
#
|
22
|
+
# Arguments are:
|
23
|
+
#
|
24
|
+
# +ystart+, +yend+: start/end y values required
|
25
|
+
# +xstart+, +xend+: start/end x values
|
26
|
+
# +base+: the curvature factor
|
27
|
+
#
|
28
|
+
#:nodoc:
|
29
|
+
def initialize(ys, ye, xs, xe, base = DEFAULT_BASE)
|
30
|
+
@y_start = ys
|
31
|
+
@y_end = ye
|
32
|
+
@x_start = xs
|
33
|
+
@x_end = xe
|
34
|
+
@base = base
|
35
|
+
setup
|
36
|
+
end
|
37
|
+
|
38
|
+
#:doc:
|
39
|
+
#
|
40
|
+
# +y(x)+:
|
41
|
+
#
|
42
|
+
# Returns a real value (forcing any complex result to its modulus) for any
|
43
|
+
# given x
|
44
|
+
#
|
45
|
+
#:nodoc:
|
46
|
+
def y(x)
|
47
|
+
(CMath::log(self.a*x + self.b) + self.c).abs # we want a real number result, no complex please
|
48
|
+
end
|
49
|
+
|
50
|
+
def label
|
51
|
+
"base: #{self.base}"
|
52
|
+
end
|
53
|
+
|
54
|
+
class << self
|
55
|
+
|
56
|
+
#
|
57
|
+
# +from_yaml(yaml_hash)+:
|
58
|
+
#
|
59
|
+
# creates a Math::Log class from a yaml file which must have the
|
60
|
+
# relevant fields:
|
61
|
+
#
|
62
|
+
# +x_start+
|
63
|
+
# +x_end+
|
64
|
+
# +y_start+
|
65
|
+
# +y_end+
|
66
|
+
# +base+
|
67
|
+
#
|
68
|
+
def from_yaml(yh)
|
69
|
+
args = [yh['y_start'], yh['y_end'], yh['x_start'], yh['x_end'], yh['base']]
|
70
|
+
new(*args)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def setup
|
78
|
+
@c = self.y_end + self.base
|
79
|
+
|
80
|
+
log_sv = self.y_start - self.c # start value of the exponential
|
81
|
+
log_ev = self.y_end - self.c # end value of the exponential
|
82
|
+
x_length = self.x_end - self.x_start
|
83
|
+
|
84
|
+
@a = (CMath::exp(log_ev) - CMath::exp(log_sv)) / x_length;
|
85
|
+
@b= CMath::exp(log_sv) - (self.a * x_start);
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicola Bernardini
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wavefile
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/mext/math/expon.rb
|
141
141
|
- lib/mext/math/function.rb
|
142
142
|
- lib/mext/math/line.rb
|
143
|
+
- lib/mext/math/log.rb
|
143
144
|
- lib/mext/math/stepwise.rb
|
144
145
|
- lib/mext/music.rb
|
145
146
|
- lib/mext/music/pitch_class.rb
|