From 19ec6a57a4bec20fcf14725da84dc125ad539e1f Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 15 Apr 2021 19:39:46 +0300 Subject: [PATCH] Gauss-Legendre working test --- .../integration/GaussIntegratorRuleFactory.kt | 18 +++++++++++------- .../kmath/integration/GaussIntegralTest.kt | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) 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) }