Module: IERS::Interpolation Private
- Defined in:
- lib/iers/interpolation.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
- .lagrange(xs, ys, x) ⇒ Float private
- .linear(xs, ys, x) ⇒ Float private
Class Method Details
.lagrange(xs, ys, x) ⇒ Float
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/iers/interpolation.rb', line 27 def lagrange(xs, ys, x) n = xs.size unless n == ys.size raise ArgumentError, "xs and ys must have the same size" end unless n >= 2 raise ArgumentError, "lagrange interpolation requires at least 2 points" end result = 0.0 n.times do |i| basis = 1.0 n.times do |j| next if i == j basis *= (x - xs[j]) / (xs[i] - xs[j]) end result += ys[i] * basis end result end |
.linear(xs, ys, x) ⇒ Float
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/iers/interpolation.rb', line 12 def linear(xs, ys, x) unless xs.size == 2 && ys.size == 2 raise ArgumentError, "linear interpolation requires exactly 2 points" end x0, x1 = xs y0, y1 = ys t = (x - x0) / (x1 - x0) y0 + t * (y1 - y0) end |