Class: LagrangePolynomial
- Inherits:
-
Object
- Object
- LagrangePolynomial
- Defined in:
- lib/polynomial_ruby/lagrange_polynomial.rb
Instance Attribute Summary collapse
-
#points ⇒ Object
Returns the value of attribute points.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(input) ⇒ LagrangePolynomial
constructor
A new instance of LagrangePolynomial.
Constructor Details
#initialize(input) ⇒ LagrangePolynomial
Returns a new instance of LagrangePolynomial.
4 5 6 7 |
# File 'lib/polynomial_ruby/lagrange_polynomial.rb', line 4 def initialize(input) self.points = input.map { |a, _| a } self.values = input.map { |_, b| b } end |
Instance Attribute Details
#points ⇒ Object
Returns the value of attribute points.
2 3 4 |
# File 'lib/polynomial_ruby/lagrange_polynomial.rb', line 2 def points @points end |
#values ⇒ Object
Returns the value of attribute values.
2 3 4 |
# File 'lib/polynomial_ruby/lagrange_polynomial.rb', line 2 def values @values end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 |
# File 'lib/polynomial_ruby/lagrange_polynomial.rb', line 9 def call basis_polynomials.zip(values) .map { |p, v| p * v } .reduce(:+) end |