diff --git a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt index a3adacc04..678e6bf0a 100644 --- a/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt +++ b/kmath-functions/src/commonMain/kotlin/space/kscience/kmath/integration/GaussIntegratorRuleFactory.kt @@ -2,7 +2,6 @@ package space.kscience.kmath.integration import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.Field -import space.kscience.kmath.operations.Ring import space.kscience.kmath.structures.* import kotlin.jvm.Synchronized import kotlin.math.ulp @@ -27,14 +26,19 @@ public fun > GaussIntegratorRuleFactory.build( range: ClosedRange, ): Pair, Buffer> { val normalized = build(numPoints) - val points = with(algebra) { + with(algebra) { val length = range.endInclusive - range.start - normalized.first.map(bufferFactory) { - range.start + length / 2 + length * it/2 - } - } - return points to normalized.second + val points = normalized.first.map(bufferFactory) { + range.start + length / 2 + length * it / 2 + } + + val weights = normalized.second.map(bufferFactory) { + it * length / 2 + } + + return points to weights + } } 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 7c33ea73f..5fccd8aa9 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 @@ -23,7 +23,7 @@ class GaussIntegralTest { 0.0 } } - assertEquals(20.0, res.value!!, 0.1) + assertEquals(20.0, res.value!!, 0.5) }