Class: Math::Expon

Inherits:
Function show all
Defined in:
lib/mext/math/expon.rb

Constant Summary collapse

DEFAULT_TAU =

DEFAULT_TAU: default exponential curvature factor for expon()

0.01

Instance Attribute Summary collapse

Attributes inherited from Function

#x_end, #x_start

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#xy

Methods included from Mext::Utilities

included

Constructor Details

#initialize(ys, ye, xs, xe, tau = DEFAULT_TAU) ⇒ Expon

Math::Expon.new(ystart, yend, xstart, xend, tau = DEFAULT_TAU):

exponential curve ‘y = e^(a*x + b) + c` where:

‘c = yend + tau`

Arguments are:

ystart, yend: start/end y values required xstart, xend: start/end x values tau: the curvature factor

:nodoc:



29
30
31
32
33
34
35
36
# File 'lib/mext/math/expon.rb', line 29

def initialize(ys, ye, xs, xe, tau = DEFAULT_TAU)
  @y_start = ys
  @y_end   = ye
  @x_start = xs
  @x_end   = xe
  @tau     = tau
  setup
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a.



8
9
10
# File 'lib/mext/math/expon.rb', line 8

def a
  @a
end

#bObject (readonly)

Returns the value of attribute b.



8
9
10
# File 'lib/mext/math/expon.rb', line 8

def b
  @b
end

#cObject (readonly)

Returns the value of attribute c.



8
9
10
# File 'lib/mext/math/expon.rb', line 8

def c
  @c
end

#tauObject (readonly)

Returns the value of attribute tau.



7
8
9
# File 'lib/mext/math/expon.rb', line 7

def tau
  @tau
end

#y_endObject (readonly)

Returns the value of attribute y_end.



7
8
9
# File 'lib/mext/math/expon.rb', line 7

def y_end
  @y_end
end

#y_startObject (readonly)

Returns the value of attribute y_start.



7
8
9
# File 'lib/mext/math/expon.rb', line 7

def y_start
  @y_start
end

Class Method Details

.from_yaml(yh) ⇒ Object

from_yaml(yaml_hash):

creates a Math::Expon class from a yaml file which must have the relevant fields:

x_start x_end y_start y_end tau



68
69
70
71
# File 'lib/mext/math/expon.rb', line 68

def from_yaml(yh)
  args = [yh['y_start'], yh['y_end'], yh['x_start'], yh['x_end'], yh['tau']]
  new(*args)
end

Instance Method Details

#labelObject



50
51
52
# File 'lib/mext/math/expon.rb', line 50

def label
  "tau: #{self.tau}"
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/expon.rb', line 46

def y(x)
  (CMath::exp(self.a*x + self.b) + self.c).abs   # we want a real number result, no complex please
end