class Mathmas::Function
Attributes
name[R]
vals[R]
Public Class Methods
new(name, vals)
click to toggle source
# File lib/mathmas/core/function.rb, line 6 def initialize(name, vals) raise "This is not function" unless vals.all?{|val| val.is_a?(Mathmas::Variable)} @expr = nil @name = name @vals = vals Mathmas.add_function self end
Public Instance Methods
<=(expr)
click to toggle source
# File lib/mathmas/core/function.rb, line 14 def <=(expr) raise "The right hand of Mathmas::Function#<- should be an instance of Mathmas::Basic" unless expr.is_a?(Mathmas::Basic) @expr = expr end
exec(*args)
click to toggle source
@example
f(x) = 1/x f.exec(x: 3) #-> 1/3 f.exec(3) #-> 1/3
# File lib/mathmas/core/function.rb, line 34 def exec(*args) if args.length == 1 && args[0].is_a?(Hash) @expr.exec(args[0]) else symbols = @vals.map{|val| val.symbol} hash = args.zip(symbols).reduce({}){|memo, pair| memo[pair[1]] = pair[0]; memo} @expr.exec(hash) end end
plot(args)
click to toggle source
# File lib/mathmas/plot/function.rb, line 47 def plot(args) Mathmas.plot_function(self, args) end
to_s()
click to toggle source
# File lib/mathmas/core/function.rb, line 19 def to_s strs = @vals.map{|val| val.to_s} @name.to_s + "(#{ strs.join(",") }) = " + @expr.to_s end
to_tex()
click to toggle source
# File lib/mathmas/core/function.rb, line 24 def to_tex strs = @vals.map{|val| val.to_s} @name.to_s + "(#{ strs.join(",") }) = " + @expr.to_tex end