Browse Source

quadrature: some methods are now static

Signed-off-by: Christoph Ruegg <git@cdrnet.ch>
pull/2/head
Christoph Ruegg 17 years ago
parent
commit
f2e442d54a
  1. 20
      src/Managed.UnitTests/IntegrationTests/IntegrationTest.cs
  2. 7
      src/Managed/Integration/Algorithms/DoubleExponentialTransformation.cs
  3. 10
      src/Managed/Integration/Algorithms/NewtonCotesTrapeziumRule.cs
  4. 6
      src/Managed/Integration/Algorithms/SimpsonRule.cs

20
src/Managed.UnitTests/IntegrationTests/IntegrationTest.cs

@ -82,11 +82,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
[Test] [Test]
public void TrapeziumRuleSupportsTwoPointIntegration() public void TrapeziumRuleSupportsTwoPointIntegration()
{ {
var algorithm = new NewtonCotesTrapeziumRule();
Assert.AreApproximatelyEqual( Assert.AreApproximatelyEqual(
TargetAreaA, TargetAreaA,
algorithm.IntegrateTwoPoint(TargetFunctionA, StartA, StopA), NewtonCotesTrapeziumRule.IntegrateTwoPoint(TargetFunctionA, StartA, StopA),
0.4 * TargetAreaA, 0.4 * TargetAreaA,
"Direct (1 Partition)"); "Direct (1 Partition)");
} }
@ -99,11 +97,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
[Row(1000, 1.5e-6)] [Row(1000, 1.5e-6)]
public void TrapeziumRuleSupportsCompositeIntegration(int partitions, double maxRelativeError) public void TrapeziumRuleSupportsCompositeIntegration(int partitions, double maxRelativeError)
{ {
var algorithm = new NewtonCotesTrapeziumRule();
Assert.AreApproximatelyEqual( Assert.AreApproximatelyEqual(
TargetAreaA, TargetAreaA,
algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions), NewtonCotesTrapeziumRule.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions),
maxRelativeError * TargetAreaA, maxRelativeError * TargetAreaA,
"Composite {0} Partitions", partitions); "Composite {0} Partitions", partitions);
} }
@ -114,11 +110,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
[Row(1e-10)] [Row(1e-10)]
public void TrapeziumRuleSupportsAdaptiveIntegration(double targetRelativeError) public void TrapeziumRuleSupportsAdaptiveIntegration(double targetRelativeError)
{ {
var algorithm = new NewtonCotesTrapeziumRule();
Assert.AreApproximatelyEqual( Assert.AreApproximatelyEqual(
TargetAreaA, TargetAreaA,
algorithm.IntegrateAdaptive(TargetFunctionA, StartA, StopA, targetRelativeError), NewtonCotesTrapeziumRule.IntegrateAdaptive(TargetFunctionA, StartA, StopA, targetRelativeError),
targetRelativeError * TargetAreaA, targetRelativeError * TargetAreaA,
"Adaptive {0}", targetRelativeError); "Adaptive {0}", targetRelativeError);
} }
@ -126,11 +120,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
[Test] [Test]
public void SimpsonRuleSupportsThreePointIntegration() public void SimpsonRuleSupportsThreePointIntegration()
{ {
var algorithm = new SimpsonRule();
Assert.AreApproximatelyEqual( Assert.AreApproximatelyEqual(
TargetAreaA, TargetAreaA,
algorithm.IntegrateThreePoint(TargetFunctionA, StartA, StopA), SimpsonRule.IntegrateThreePoint(TargetFunctionA, StartA, StopA),
0.2 * TargetAreaA, 0.2 * TargetAreaA,
"Direct (2 Partitions)"); "Direct (2 Partitions)");
} }
@ -143,11 +135,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
[Row(1000, 5e-11)] [Row(1000, 5e-11)]
public void SimpsonRuleSupportsCompositeIntegration(int partitions, double maxRelativeError) public void SimpsonRuleSupportsCompositeIntegration(int partitions, double maxRelativeError)
{ {
var algorithm = new SimpsonRule();
Assert.AreApproximatelyEqual( Assert.AreApproximatelyEqual(
TargetAreaA, TargetAreaA,
algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions), SimpsonRule.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions),
maxRelativeError * TargetAreaA, maxRelativeError * TargetAreaA,
"Composite {0} Partitions", partitions); "Composite {0} Partitions", partitions);
} }

7
src/Managed/Integration/Algorithms/DoubleExponentialTransformation.cs

@ -491,11 +491,6 @@ namespace MathNet.Numerics.Integration.Algorithms
/// </summary> /// </summary>
private const int NumberOfMaximumLevels = 10; private const int NumberOfMaximumLevels = 10;
/// <summary>
/// Internal Trapezium Rule.
/// </summary>
private readonly NewtonCotesTrapeziumRule _trapezium = new NewtonCotesTrapeziumRule();
/// <summary> /// <summary>
/// Abscissa vector per level provider. /// Abscissa vector per level provider.
/// </summary> /// </summary>
@ -526,7 +521,7 @@ namespace MathNet.Numerics.Integration.Algorithms
_levelWeights = ProvideLevelWeights(); _levelWeights = ProvideLevelWeights();
} }
return _trapezium.IntegrateAdaptiveTransformedOdd( return NewtonCotesTrapeziumRule.IntegrateAdaptiveTransformedOdd(
f, f,
intervalBegin, intervalBegin,
intervalEnd, intervalEnd,

10
src/Managed/Integration/Algorithms/NewtonCotesTrapeziumRule.cs

@ -38,7 +38,7 @@ namespace MathNet.Numerics.Integration.Algorithms
/// <remarks> /// <remarks>
/// <a href="http://en.wikipedia.org/wiki/Trapezium_rule">Wikipedia - Trapezium Rule</a> /// <a href="http://en.wikipedia.org/wiki/Trapezium_rule">Wikipedia - Trapezium Rule</a>
/// </remarks> /// </remarks>
public class NewtonCotesTrapeziumRule public static class NewtonCotesTrapeziumRule
{ {
/// <summary> /// <summary>
/// Direct 2-point approximation of the definite integral in the provided interval by the trapezium rule. /// 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
/// <param name="intervalBegin">Where the interval starts, inclusive and finite.</param> /// <param name="intervalBegin">Where the interval starts, inclusive and finite.</param>
/// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param> /// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param>
/// <returns>Approximation of the finite integral in the given interval.</returns> /// <returns>Approximation of the finite integral in the given interval.</returns>
public double IntegrateTwoPoint( public static double IntegrateTwoPoint(
Func<double, double> f, Func<double, double> f,
double intervalBegin, double intervalBegin,
double intervalEnd) double intervalEnd)
@ -63,7 +63,7 @@ namespace MathNet.Numerics.Integration.Algorithms
/// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param> /// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param>
/// <param name="numberOfPartitions">Number of composite subdivision partitions.</param> /// <param name="numberOfPartitions">Number of composite subdivision partitions.</param>
/// <returns>Approximation of the finite integral in the given interval.</returns> /// <returns>Approximation of the finite integral in the given interval.</returns>
public double IntegrateComposite( public static double IntegrateComposite(
Func<double, double> f, Func<double, double> f,
double intervalBegin, double intervalBegin,
double intervalEnd, double intervalEnd,
@ -96,7 +96,7 @@ namespace MathNet.Numerics.Integration.Algorithms
/// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param> /// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param>
/// <param name="targetRelativeError">The expected relative accuracy of the approximation.</param> /// <param name="targetRelativeError">The expected relative accuracy of the approximation.</param>
/// <returns>Approximation of the finite integral in the given interval.</returns> /// <returns>Approximation of the finite integral in the given interval.</returns>
public double IntegrateAdaptive( public static double IntegrateAdaptive(
Func<double, double> f, Func<double, double> f,
double intervalBegin, double intervalBegin,
double intervalEnd, double intervalEnd,
@ -138,7 +138,7 @@ namespace MathNet.Numerics.Integration.Algorithms
/// <param name="levelOneStep">First Level Step</param> /// <param name="levelOneStep">First Level Step</param>
/// <param name="targetRelativeError">The expected relative accuracy of the approximation.</param> /// <param name="targetRelativeError">The expected relative accuracy of the approximation.</param>
/// <returns>Approximation of the finite integral in the given interval.</returns> /// <returns>Approximation of the finite integral in the given interval.</returns>
public double IntegrateAdaptiveTransformedOdd( public static double IntegrateAdaptiveTransformedOdd(
Func<double, double> f, Func<double, double> f,
double intervalBegin, double intervalBegin,
double intervalEnd, double intervalEnd,

6
src/Managed/Integration/Algorithms/SimpsonRule.cs

@ -35,7 +35,7 @@ namespace MathNet.Numerics.Integration.Algorithms
/// <summary> /// <summary>
/// Approximation algorithm for definite integrals by Simpson's rule. /// Approximation algorithm for definite integrals by Simpson's rule.
/// </summary> /// </summary>
public class SimpsonRule public static class SimpsonRule
{ {
/// <summary> /// <summary>
/// Direct 3-point approximation of the definite integral in the provided interval by Simpson's rule. /// 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
/// <param name="intervalBegin">Where the interval starts, inclusive and finite.</param> /// <param name="intervalBegin">Where the interval starts, inclusive and finite.</param>
/// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param> /// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param>
/// <returns>Approximation of the finite integral in the given interval.</returns> /// <returns>Approximation of the finite integral in the given interval.</returns>
public double IntegrateThreePoint( public static double IntegrateThreePoint(
Func<double, double> f, Func<double, double> f,
double intervalBegin, double intervalBegin,
double intervalEnd) double intervalEnd)
@ -61,7 +61,7 @@ namespace MathNet.Numerics.Integration.Algorithms
/// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param> /// <param name="intervalEnd">Where the interval stops, inclusive and finite.</param>
/// <param name="numberOfPartitions">Even number of composite subdivision partitions.</param> /// <param name="numberOfPartitions">Even number of composite subdivision partitions.</param>
/// <returns>Approximation of the finite integral in the given interval.</returns> /// <returns>Approximation of the finite integral in the given interval.</returns>
public double IntegrateComposite( public static double IntegrateComposite(
Func<double, double> f, Func<double, double> f,
double intervalBegin, double intervalBegin,
double intervalEnd, double intervalEnd,

Loading…
Cancel
Save