From e6c6925209e73a766a913450fdd9c6af11ca8f06 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 16 May 2021 22:33:53 +0300 Subject: [PATCH] Fix integration borders --- .../space/kscience/kmath/integration/GaussIntegrator.kt | 2 +- .../space/kscience/kmath/integration/GaussIntegralTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt index 0038ca0f2..fcf47040e 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegrator.kt @@ -98,7 +98,7 @@ public fun GaussIntegrator.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( diff --git a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/GaussIntegralTest.kt b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/GaussIntegralTest.kt index 1f9f7aedf..6195d0ac6 100644 --- a/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/GaussIntegralTest.kt +++ b/kmath-functions/src/commonTest/kotlin/space/kscience/kmath/integration/GaussIntegralTest.kt @@ -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) }