Sha256: 5f06b5528a43e3c2fcd5712d7a39957e58a9cf3f579eb6bd50e5ee3b7a393c0a
Contents?: true
Size: 867 Bytes
Versions: 1
Compression:
Stored size: 867 Bytes
Contents
module Dydx module Algebra class Inverse include Helper attr_accessor :x, :operator def initialize(x, operator) @x, @operator = x, operator end def to_s case operator when :+ then "( - #{x} )" when :* then "( 1 / #{x} )" end end def subst(hash = {}) case operator when :+ then x.subst(hash) * -1 when :* then x.subst(hash) ** -1 end end def to_f case operator when :+ then x.to_f * -1 when :* then x.to_f ** -1 end end def differentiate(sym=:x) case operator when :+ inverse(x.differentiate(sym), :+) when :* inverse(x.differentiate(sym) * inverse(x ^ 2, :*), :+) end end alias_method :d, :differentiate end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dydx-0.1.314 | lib/dydx/algebra/inverse.rb |