Class: Math::Log
Constant Summary collapse
- DEFAULT_BASE =
DEFAULT_BASE
: default logarithmic curvature factor for Log() Math::E
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#c ⇒ Object
readonly
Returns the value of attribute c.
-
#y_end ⇒ Object
readonly
Returns the value of attribute y_end.
-
#y_start ⇒ Object
readonly
Returns the value of attribute y_start.
Attributes inherited from Function
Class Method Summary collapse
-
.from_yaml(yh) ⇒ Object
from_yaml(yaml_hash):.
Instance Method Summary collapse
-
#initialize(ys, ye, xs, xe, base = DEFAULT_BASE) ⇒ Log
constructor
Math::Log.new(ystart, yend, xstart, xend, base = DEFAULT_BASE):.
- #label ⇒ Object
-
#y(x) ⇒ Object
:doc:.
Methods inherited from Function
Methods included from Mext::Utilities
Constructor Details
#initialize(ys, ye, xs, xe, base = DEFAULT_BASE) ⇒ Log
Math::Log.new(ystart, yend, xstart, xend, base = DEFAULT_BASE):
exponential curve ‘y = e^(a*x + b) + c` where:
‘c = yend + base`
Arguments are:
ystart
, yend
: start/end y values required xstart
, xend
: start/end x values base
: the curvature factor
:nodoc:
29 30 31 32 33 34 35 36 |
# File 'lib/mext/math/log.rb', line 29 def initialize(ys, ye, xs, xe, base = DEFAULT_BASE) @y_start = ys @y_end = ye @x_start = xs @x_end = xe @base = base setup end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
8 9 10 |
# File 'lib/mext/math/log.rb', line 8 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
8 9 10 |
# File 'lib/mext/math/log.rb', line 8 def b @b end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/mext/math/log.rb', line 7 def base @base end |
#c ⇒ Object (readonly)
Returns the value of attribute c.
8 9 10 |
# File 'lib/mext/math/log.rb', line 8 def c @c end |
#y_end ⇒ Object (readonly)
Returns the value of attribute y_end.
7 8 9 |
# File 'lib/mext/math/log.rb', line 7 def y_end @y_end end |
#y_start ⇒ Object (readonly)
Returns the value of attribute y_start.
7 8 9 |
# File 'lib/mext/math/log.rb', line 7 def y_start @y_start end |
Class Method Details
.from_yaml(yh) ⇒ Object
from_yaml(yaml_hash):
creates a Math::Log class from a yaml file which must have the relevant fields:
x_start
x_end
y_start
y_end
base
68 69 70 71 |
# File 'lib/mext/math/log.rb', line 68 def from_yaml(yh) args = [yh['y_start'], yh['y_end'], yh['x_start'], yh['x_end'], yh['base']] new(*args) end |
Instance Method Details
#label ⇒ Object
50 51 52 |
# File 'lib/mext/math/log.rb', line 50 def label "base: #{self.base}" end |
#y(x) ⇒ Object
:doc:
y(x):
Returns a real value (forcing any complex result to its modulus) for any given x
:nodoc:
46 47 48 |
# File 'lib/mext/math/log.rb', line 46 def y(x) (CMath::log(self.a*x + self.b) + self.c).abs # we want a real number result, no complex please end |