Class: Symbolic::Misc::Sum

Inherits:
Object
  • Object
show all
Includes:
Symbolic
Defined in:
lib/symbolic/sum.rb

Overview

blah

Constant Summary

Constants included from Symbolic

OPERATIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Symbolic

#*, #**, #+, #+@, #-, #-@, #/, #coerce, #factorial, #inspect, #operations, #taylor, #to_s

Constructor Details

#initialize(term, index, lb, ub) ⇒ Sum

Returns a new instance of Sum.



8
9
10
# File 'lib/symbolic/sum.rb', line 8

def initialize(term,index,lb,ub)
  @term, @index, @lb, @ub = term, index, lb, ub
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/symbolic/sum.rb', line 6

def index
  @index
end

#lbObject (readonly)

Returns the value of attribute lb.



6
7
8
# File 'lib/symbolic/sum.rb', line 6

def lb
  @lb
end

#termObject (readonly)

Returns the value of attribute term.



6
7
8
# File 'lib/symbolic/sum.rb', line 6

def term
  @term
end

#ubObject (readonly)

Returns the value of attribute ub.



6
7
8
# File 'lib/symbolic/sum.rb', line 6

def ub
  @ub
end

Class Method Details

.[](term, index, lb, ub) ⇒ Object



11
12
13
# File 'lib/symbolic/sum.rb', line 11

def Sum.[](term,index,lb,ub)
  Symbolic::Sum.new(term,index,lb,ub)
end

Instance Method Details

#diff(wrt) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/symbolic/sum.rb', line 20

def diff(wrt)
  #TODO: error if wrt is the index
  if @term.diff(wrt) != 0
    Sum.new(@term.diff(wrt),@index,@lb,@ub)
  else
    0
  end
end

#expandObject



14
15
16
# File 'lib/symbolic/sum.rb', line 14

def expand
  (lb..ub).collect{|ind| @term.subs(@index,ind)}.inject{|m,t| m + t}
end

#subs(to_replace, replacement = nil) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/symbolic/sum.rb', line 34

def subs(to_replace, replacement=nil)
  #TODO: error if to_replace is @index
  if replacement == nil and to_replace.is_a?(Hash)
	super(to_replace)
  else
	Sum.new(@term.subs(to_replace, replacement),@index,@lb,@ub)
  end
end

#valueObject



31
32
33
# File 'lib/symbolic/sum.rb', line 31

def value
  self.expand.value
end

#variablesObject



17
18
19
# File 'lib/symbolic/sum.rb', line 17

def variables
  @term.variables.reject{|var| var == @index}
end