0.1.4-dev-4 #86
@ -17,7 +17,7 @@ class LinearInterpolator<T : Comparable<T>>(override val algebra: Field<T>) : Po
|
|||||||
OrderedPiecewisePolynomial(points.x[0]).apply {
|
OrderedPiecewisePolynomial(points.x[0]).apply {
|
||||||
for (i in 0 until points.size - 1) {
|
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 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)
|
val polynomial = Polynomial(const, slope)
|
||||||
putRight(points.x[i + 1], polynomial)
|
putRight(points.x[i + 1], polynomial)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package scientifik.kmath.interpolation
|
package scientifik.kmath.interpolation
|
||||||
|
|
||||||
|
import scientifik.kmath.functions.PiecewisePolynomial
|
||||||
import scientifik.kmath.functions.asFunction
|
import scientifik.kmath.functions.asFunction
|
||||||
import scientifik.kmath.operations.RealField
|
import scientifik.kmath.operations.RealField
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
@ -15,7 +16,7 @@ class LinearInterpolatorTest {
|
|||||||
2.0 to 3.0,
|
2.0 to 3.0,
|
||||||
3.0 to 4.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)
|
val function = polynomial.asFunction(RealField)
|
||||||
|
|
||||||
assertEquals(null, function(-1.0))
|
assertEquals(null, function(-1.0))
|
||||||
|
Loading…
Reference in New Issue
Block a user