Feature/booleans #341
@ -79,4 +79,13 @@ public class OrderedPiecewisePolynomial<T : Comparable<T>>(delimiter: T) :
|
||||
public fun <T : Comparable<T>, C : Ring<T>> PiecewisePolynomial<T>.value(ring: C, arg: T): T? =
|
||||
findPiece(arg)?.value(ring, arg)
|
||||
|
||||
/**
|
||||
* Convert this polynomial to a function returning nullable value (null if argument is outside piecewise range).
|
||||
*/
|
||||
public fun <T : Comparable<T>, C : Ring<T>> PiecewisePolynomial<T>.asFunction(ring: C): (T) -> T? = { value(ring, it) }
|
||||
|
||||
/**
|
||||
* Convert this polynomial to a function using [defaultValue] for arguments outside the piecewise range.
|
||||
*/
|
||||
public fun <T : Comparable<T>, C : Ring<T>> PiecewisePolynomial<T>.asFunction(ring: C, defaultValue: T): (T) -> T =
|
||||
{ value(ring, it) ?: defaultValue }
|
||||
|
@ -42,9 +42,11 @@ public class SplineInterpolator<T : Comparable<T>>(
|
||||
val g = 2.0 * (points.x[i + 1] - points.x[i - 1]) - h[i - 1] * mu[i - 1]
|
||||
mu[i] = h[i] / g
|
||||
|
||||
z[i] =
|
||||
(3.0 * (points.y[i + 1] * h[i - 1] - points.x[i] * (points.x[i + 1] - points.x[i - 1]) + points.y[i - 1] * h[i]) / (h[i - 1] * h[i])
|
||||
- h[i - 1] * z[i - 1]) / g
|
||||
z[i] = (3.0 * (points.y[i + 1] * h[i - 1]
|
||||
- points.x[i] * (points.x[i + 1] - points.x[i - 1])
|
||||
+ points.y[i - 1] * h[i]) / (h[i - 1] * h[i])
|
||||
- h[i - 1] * z[i - 1]
|
||||
) / g
|
||||
}
|
||||
|
||||
// cubic spline coefficients -- b is linear, c quadratic, d is cubic (original y's are constants)
|
||||
|
Loading…
Reference in New Issue
Block a user