Feature/booleans #341

Merged
altavir merged 13 commits from feature/booleans into dev 2021-05-19 03:36:37 +03:00
2 changed files with 14 additions and 3 deletions
Showing only changes of commit 6eb95f26eb - Show all commits

View File

@ -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 }

View File

@ -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)