Module: ChebyRuby::Differentiation

Included in:
FiniteDifferencing
Defined in:
lib/chebyruby/differentiation.rb

Overview

Module/Mixin for numeric differentiation methods. As of right now it is only mixed-in to @see [FiniteDifferencing] but will likely be mixed into more in the future.

Instance Method Summary collapse

Instance Method Details

#slope(func, a, b) ⇒ Float

A crude method to calculate the “slope” of a function over the span of two points. The formula used is: <pre>(f(b) - f(a))/(b - a)</pre>

Parameters:

  • func (UnivariateFunction)

    the univariate function to be used.

  • a (Numeric)

    one of the values in the domain of func

  • b (Numeric)

    the other value in the domain of func

Returns:

  • (Float)

    the slope as described above



15
16
17
# File 'lib/chebyruby/differentiation.rb', line 15

def slope(func, a, b)
  (func.value(b) - func.value(a))/(b-a).to_f
end