Fix linear interpolator const

This commit is contained in:
Alexander Nozik 2020-02-13 16:21:41 +03:00
parent 068b90e7ab
commit e00a66ca42
2 changed files with 3 additions and 2 deletions

View File

@ -17,7 +17,7 @@ class LinearInterpolator<T : Comparable<T>>(override val algebra: Field<T>) : Po
OrderedPiecewisePolynomial(points.x[0]).apply {
for (i in 0 until points.size - 1) {
val slope = (points.y[i + 1] - points.y[i]) / (points.x[i + 1] - points.x[i])
val const = points.x[i] - slope * points.x[i]
val const = points.y[i] - slope * points.x[i]
val polynomial = Polynomial(const, slope)
putRight(points.x[i + 1], polynomial)
}

View File

@ -1,5 +1,6 @@
package scientifik.kmath.interpolation
import scientifik.kmath.functions.PiecewisePolynomial
import scientifik.kmath.functions.asFunction
import scientifik.kmath.operations.RealField
import kotlin.test.Test
@ -15,7 +16,7 @@ class LinearInterpolatorTest {
2.0 to 3.0,
3.0 to 4.0
)
val polynomial = LinearInterpolator(RealField).interpolatePolynomials(data)
val polynomial: PiecewisePolynomial<Double> = LinearInterpolator(RealField).interpolatePolynomials(data)
val function = polynomial.asFunction(RealField)
assertEquals(null, function(-1.0))