Class: Log

Inherits:
Equation show all
Defined in:
lib/symcalc.rb

Overview

Implements the logarithm operation in SymCalc

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Equation

#*, #**, #+, #-, #/, #__simplify__, #coerce, #derivative, #eval, #inspect, #simplify, #to_s

Constructor Details

#initialize(base, eq) ⇒ Log

Implements the subtraction operation in SymCalc Accepts the base and equation arguments

Example:

x = SymCalc.var(“x”) fx = Log.new 10, x ** 2



787
788
789
790
# File 'lib/symcalc.rb', line 787

def initialize base, eq
  @base = to_equation(base)
  @eq = to_equation(eq)
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



777
778
779
# File 'lib/symcalc.rb', line 777

def base
  @base
end

#eqObject

Returns the value of attribute eq.



777
778
779
# File 'lib/symcalc.rb', line 777

def eq
  @eq
end

Instance Method Details

#__derivative__(variable: nil) ⇒ Object



800
801
802
# File 'lib/symcalc.rb', line 800

def __derivative__ variable: nil
  return 1 / (Ln.new(@base) * @eq) * @eq.derivative(variable: variable)
end

#__eval__(var_hash) ⇒ Object



796
797
798
# File 'lib/symcalc.rb', line 796

def __eval__ var_hash
  return Math.log(@eq.eval(var_hash), @base.eval(var_hash))
end

#__get_m_elements__(var_hash) ⇒ Object



804
805
806
807
808
809
810
811
# File 'lib/symcalc.rb', line 804

def __get_m_elements__ var_hash
  if var_hash.keys.include? self
    var_hash[self] += 1
  else
    var_hash[self] = 1
  end
  return var_hash
end

#all_variablesObject



813
814
815
# File 'lib/symcalc.rb', line 813

def all_variables
  return (@base.all_variables + @eq.all_variables).uniq
end

#displayObject



792
793
794
# File 'lib/symcalc.rb', line 792

def display
  return "log_(#{@base.display})(#{@eq.display})"
end