Fix integration borders

This commit is contained in:
Alexander Nozik 2021-05-16 22:33:53 +03:00
parent f86a6130e0
commit e6c6925209
2 changed files with 3 additions and 3 deletions

View File

@ -98,7 +98,7 @@ public fun <T : Any> GaussIntegrator<T>.integrate(
require(intervals > 0) { "Number of intervals must be positive" }
val rangeSize = (range.endInclusive - range.start) / intervals
val ranges = UnivariateIntegrandRanges(
(0 until intervals).map { i -> (rangeSize * i)..(rangeSize * (i + 1)) to order }
(0 until intervals).map { i -> (range.start + rangeSize * i)..(range.start + rangeSize * (i + 1)) to order }
)
return integrate(
UnivariateIntegrand(

View File

@ -24,14 +24,14 @@ class GaussIntegralTest {
@Test
fun gaussUniform() {
val res = DoubleField.integrator.integrate(0.0..100.0) { x ->
val res = DoubleField.integrator.integrate(35.0..100.0) { x ->
if(x in 30.0..50.0){
1.0
} else {
0.0
}
}
assertEquals(20.0, res.valueOrNull!!, 0.5)
assertEquals(15.0, res.valueOrNull!!, 0.5)
}