From f2e442d54aec7435ecb86bf44e2793c9d232f117 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Mon, 27 Jul 2009 21:56:40 +0800 Subject: [PATCH] quadrature: some methods are now static Signed-off-by: Christoph Ruegg --- .../IntegrationTests/IntegrationTest.cs | 20 +++++-------------- .../DoubleExponentialTransformation.cs | 7 +------ .../Algorithms/NewtonCotesTrapeziumRule.cs | 10 +++++----- .../Integration/Algorithms/SimpsonRule.cs | 6 +++--- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/Managed.UnitTests/IntegrationTests/IntegrationTest.cs b/src/Managed.UnitTests/IntegrationTests/IntegrationTest.cs index c2ee5788..e2dee5d8 100644 --- a/src/Managed.UnitTests/IntegrationTests/IntegrationTest.cs +++ b/src/Managed.UnitTests/IntegrationTests/IntegrationTest.cs @@ -82,11 +82,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests [Test] public void TrapeziumRuleSupportsTwoPointIntegration() { - var algorithm = new NewtonCotesTrapeziumRule(); - Assert.AreApproximatelyEqual( TargetAreaA, - algorithm.IntegrateTwoPoint(TargetFunctionA, StartA, StopA), + NewtonCotesTrapeziumRule.IntegrateTwoPoint(TargetFunctionA, StartA, StopA), 0.4 * TargetAreaA, "Direct (1 Partition)"); } @@ -99,11 +97,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests [Row(1000, 1.5e-6)] public void TrapeziumRuleSupportsCompositeIntegration(int partitions, double maxRelativeError) { - var algorithm = new NewtonCotesTrapeziumRule(); - Assert.AreApproximatelyEqual( TargetAreaA, - algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions), + NewtonCotesTrapeziumRule.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions), maxRelativeError * TargetAreaA, "Composite {0} Partitions", partitions); } @@ -114,11 +110,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests [Row(1e-10)] public void TrapeziumRuleSupportsAdaptiveIntegration(double targetRelativeError) { - var algorithm = new NewtonCotesTrapeziumRule(); - Assert.AreApproximatelyEqual( TargetAreaA, - algorithm.IntegrateAdaptive(TargetFunctionA, StartA, StopA, targetRelativeError), + NewtonCotesTrapeziumRule.IntegrateAdaptive(TargetFunctionA, StartA, StopA, targetRelativeError), targetRelativeError * TargetAreaA, "Adaptive {0}", targetRelativeError); } @@ -126,11 +120,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests [Test] public void SimpsonRuleSupportsThreePointIntegration() { - var algorithm = new SimpsonRule(); - Assert.AreApproximatelyEqual( TargetAreaA, - algorithm.IntegrateThreePoint(TargetFunctionA, StartA, StopA), + SimpsonRule.IntegrateThreePoint(TargetFunctionA, StartA, StopA), 0.2 * TargetAreaA, "Direct (2 Partitions)"); } @@ -143,11 +135,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests [Row(1000, 5e-11)] public void SimpsonRuleSupportsCompositeIntegration(int partitions, double maxRelativeError) { - var algorithm = new SimpsonRule(); - Assert.AreApproximatelyEqual( TargetAreaA, - algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions), + SimpsonRule.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions), maxRelativeError * TargetAreaA, "Composite {0} Partitions", partitions); } diff --git a/src/Managed/Integration/Algorithms/DoubleExponentialTransformation.cs b/src/Managed/Integration/Algorithms/DoubleExponentialTransformation.cs index f9af64ca..e9458a0c 100644 --- a/src/Managed/Integration/Algorithms/DoubleExponentialTransformation.cs +++ b/src/Managed/Integration/Algorithms/DoubleExponentialTransformation.cs @@ -491,11 +491,6 @@ namespace MathNet.Numerics.Integration.Algorithms /// private const int NumberOfMaximumLevels = 10; - /// - /// Internal Trapezium Rule. - /// - private readonly NewtonCotesTrapeziumRule _trapezium = new NewtonCotesTrapeziumRule(); - /// /// Abscissa vector per level provider. /// @@ -526,7 +521,7 @@ namespace MathNet.Numerics.Integration.Algorithms _levelWeights = ProvideLevelWeights(); } - return _trapezium.IntegrateAdaptiveTransformedOdd( + return NewtonCotesTrapeziumRule.IntegrateAdaptiveTransformedOdd( f, intervalBegin, intervalEnd, diff --git a/src/Managed/Integration/Algorithms/NewtonCotesTrapeziumRule.cs b/src/Managed/Integration/Algorithms/NewtonCotesTrapeziumRule.cs index d989f58d..d2b848c9 100644 --- a/src/Managed/Integration/Algorithms/NewtonCotesTrapeziumRule.cs +++ b/src/Managed/Integration/Algorithms/NewtonCotesTrapeziumRule.cs @@ -38,7 +38,7 @@ namespace MathNet.Numerics.Integration.Algorithms /// /// Wikipedia - Trapezium Rule /// - public class NewtonCotesTrapeziumRule + public static class NewtonCotesTrapeziumRule { /// /// Direct 2-point approximation of the definite integral in the provided interval by the trapezium rule. @@ -47,7 +47,7 @@ namespace MathNet.Numerics.Integration.Algorithms /// Where the interval starts, inclusive and finite. /// Where the interval stops, inclusive and finite. /// Approximation of the finite integral in the given interval. - public double IntegrateTwoPoint( + public static double IntegrateTwoPoint( Func f, double intervalBegin, double intervalEnd) @@ -63,7 +63,7 @@ namespace MathNet.Numerics.Integration.Algorithms /// Where the interval stops, inclusive and finite. /// Number of composite subdivision partitions. /// Approximation of the finite integral in the given interval. - public double IntegrateComposite( + public static double IntegrateComposite( Func f, double intervalBegin, double intervalEnd, @@ -96,7 +96,7 @@ namespace MathNet.Numerics.Integration.Algorithms /// Where the interval stops, inclusive and finite. /// The expected relative accuracy of the approximation. /// Approximation of the finite integral in the given interval. - public double IntegrateAdaptive( + public static double IntegrateAdaptive( Func f, double intervalBegin, double intervalEnd, @@ -138,7 +138,7 @@ namespace MathNet.Numerics.Integration.Algorithms /// First Level Step /// The expected relative accuracy of the approximation. /// Approximation of the finite integral in the given interval. - public double IntegrateAdaptiveTransformedOdd( + public static double IntegrateAdaptiveTransformedOdd( Func f, double intervalBegin, double intervalEnd, diff --git a/src/Managed/Integration/Algorithms/SimpsonRule.cs b/src/Managed/Integration/Algorithms/SimpsonRule.cs index 98982b8a..1d2def00 100644 --- a/src/Managed/Integration/Algorithms/SimpsonRule.cs +++ b/src/Managed/Integration/Algorithms/SimpsonRule.cs @@ -35,7 +35,7 @@ namespace MathNet.Numerics.Integration.Algorithms /// /// Approximation algorithm for definite integrals by Simpson's rule. /// - public class SimpsonRule + public static class SimpsonRule { /// /// Direct 3-point approximation of the definite integral in the provided interval by Simpson's rule. @@ -44,7 +44,7 @@ namespace MathNet.Numerics.Integration.Algorithms /// Where the interval starts, inclusive and finite. /// Where the interval stops, inclusive and finite. /// Approximation of the finite integral in the given interval. - public double IntegrateThreePoint( + public static double IntegrateThreePoint( Func f, double intervalBegin, double intervalEnd) @@ -61,7 +61,7 @@ namespace MathNet.Numerics.Integration.Algorithms /// Where the interval stops, inclusive and finite. /// Even number of composite subdivision partitions. /// Approximation of the finite integral in the given interval. - public double IntegrateComposite( + public static double IntegrateComposite( Func f, double intervalBegin, double intervalEnd,