Class: Log
Overview
Implements the logarithm operation in SymCalc
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#eq ⇒ Object
Returns the value of attribute eq.
Instance Method Summary collapse
- #__derivative__(variable: nil) ⇒ Object
- #__eval__(var_hash) ⇒ Object
- #__get_m_elements__(var_hash) ⇒ Object
- #all_variables ⇒ Object
- #display ⇒ Object
-
#initialize(base, eq) ⇒ Log
constructor
Implements the subtraction operation in SymCalc Accepts the base and equation arguments.
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
#base ⇒ Object
Returns the value of attribute base.
777 778 779 |
# File 'lib/symcalc.rb', line 777 def base @base end |
#eq ⇒ Object
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_variables ⇒ Object
813 814 815 |
# File 'lib/symcalc.rb', line 813 def all_variables return (@base.all_variables + @eq.all_variables).uniq end |
#display ⇒ Object
792 793 794 |
# File 'lib/symcalc.rb', line 792 def display return "log_(#{@base.display})(#{@eq.display})" end |