Class: Pbw::Utils::Polynomial

Inherits:
Object
  • Object
show all
Defined in:
lib/pbw/utils/polynomial.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yarr) ⇒ Polynomial

Returns a new instance of Polynomial.



4
5
6
# File 'lib/pbw/utils/polynomial.rb', line 4

def initialize (yarr)
				@coefficients = yarr
end

Instance Attribute Details

#coefficientsObject (readonly)

Returns the value of attribute coefficients.



8
9
10
# File 'lib/pbw/utils/polynomial.rb', line 8

def coefficients
  @coefficients
end

Class Method Details

.mkroll(n) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/pbw/utils/polynomial.rb', line 10

def self.mkroll (n)
				x = [0]

				(1..n).each do |i|
 	x[i] = 1
				end

				::Pbw::Utils::Polynomial.new(x)
end

Instance Method Details

#*(other) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pbw/utils/polynomial.rb', line 20

def *(other)
				noob = []

				@coefficients.each_with_index do |xi, i|
 	other.coefficients.each_with_index do |yj, j|
cell = i + j

if noob[cell].nil?
  		noob[cell] = 0
end

noob[cell] += xi * yj
 	end
				end

				::Pbw::Utils::Polynomial.new(noob)
end