diff --git a/kmath-functions/src/commonMain/kotlin/scientifik/kmath/interpolation/LinearInterpolator.kt b/kmath-functions/src/commonMain/kotlin/scientifik/kmath/interpolation/LinearInterpolator.kt index 9467da421..98beb4391 100644 --- a/kmath-functions/src/commonMain/kotlin/scientifik/kmath/interpolation/LinearInterpolator.kt +++ b/kmath-functions/src/commonMain/kotlin/scientifik/kmath/interpolation/LinearInterpolator.kt @@ -17,7 +17,7 @@ class LinearInterpolator>(override val algebra: Field) : 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) } diff --git a/kmath-functions/src/commonTest/kotlin/scientifik/kmath/interpolation/LinearInterpolatorTest.kt b/kmath-functions/src/commonTest/kotlin/scientifik/kmath/interpolation/LinearInterpolatorTest.kt index 6d35d19f1..23acd835c 100644 --- a/kmath-functions/src/commonTest/kotlin/scientifik/kmath/interpolation/LinearInterpolatorTest.kt +++ b/kmath-functions/src/commonTest/kotlin/scientifik/kmath/interpolation/LinearInterpolatorTest.kt @@ -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 = LinearInterpolator(RealField).interpolatePolynomials(data) val function = polynomial.asFunction(RealField) assertEquals(null, function(-1.0))