Class: Abs
Overview
Implements the absolute value operation in SymCalc
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Equation
#*, #**, #+, #-, #/, #coerce, #derivative, #eval, #inspect, #simplify, #sub, #to_s
Constructor Details
#initialize(eq) ⇒ Abs
Returns a new instance of Abs.
908
909
910
|
# File 'lib/symcalc.rb', line 908
def initialize eq
@eq = to_equation(eq)
end
|
Instance Attribute Details
#eq ⇒ Object
Returns the value of attribute eq.
906
907
908
|
# File 'lib/symcalc.rb', line 906
def eq
@eq
end
|
Instance Method Details
#__derivative__(variable: nil) ⇒ Object
920
921
922
|
# File 'lib/symcalc.rb', line 920
def __derivative__ variable: nil
return @eq / Abs.new(@eq) * @eq.derivative(variable: variable)
end
|
#__eval__(var_hash) ⇒ Object
916
917
918
|
# File 'lib/symcalc.rb', line 916
def __eval__ var_hash
return @eq.eval(var_hash).abs
end
|
#__get_m_elements__(var_hash) ⇒ Object
928
929
930
931
932
933
934
935
|
# File 'lib/symcalc.rb', line 928
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
|
#__simplify__ ⇒ Object
924
925
926
|
# File 'lib/symcalc.rb', line 924
def __simplify__
return Abs.new(@eq.__simplify__)
end
|
#__sub__(original, replacement) ⇒ Object
948
949
950
951
|
# File 'lib/symcalc.rb', line 948
def __sub__ original, replacement
return to_equation(replacement) if self == to_equation(original)
return Abs.new(@eq.__sub__(original, replacement))
end
|
#all_variables ⇒ Object
944
945
946
|
# File 'lib/symcalc.rb', line 944
def all_variables
return @eq.all_variables
end
|
#display ⇒ Object
912
913
914
|
# File 'lib/symcalc.rb', line 912
def display
return "|#{@eq.display}|"
end
|