Sha256: 8dce934cf8298d03387473f38d26914e6db0fb388f3970e72bf2dd77e7578083

Contents?: true

Size: 624 Bytes

Versions: 2

Compression:

Stored size: 624 Bytes

Contents

module Dydx
  class Function
    attr_accessor :algebra, :vars
    def initialize(*vars)
      @vars = vars
    end

    def <=(algebra)
      @algebra = algebra
      self
    end

    def evalue(nums)
      subst_hash = Hash[*[@vars, nums].transpose.flatten]
      begin
        @algebra.subst(subst_hash).to_f
      rescue ArgumentError
        eval(@algebra.subst(subst_hash).to_s)
      end
    end

    def differentiate(sym = :x)
      @algebra.differentiate(sym)
    end
    alias_method :d, :differentiate

    def to_s
      algebra.to_s
    end

    def ==(function)
      to_s == function.to_s
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dydx-0.2.7000001 lib/dydx/function.rb
dydx-0.2.7000000 lib/dydx/function.rb