Esempio n. 1
0
        public void GetValueWithState_ThreeTimesXToThePowerOf3_BenchmarkResult(
            [Values(10, 25, 50, 100)]
            int initialOrder,
            [Values(5, 10, 25)]
            int orderStepSize)
        {
            var gaussTschebyscheffIntegrator = new GaussTschebyscheffIntegrator(initialOrder, orderStepSize);
            var numericalIntegrator          = gaussTschebyscheffIntegrator.Create();

            double lowerBound = -1.0;
            double upperBound = 1.0;

            Assert.That(numericalIntegrator.TrySetBounds(lowerBound, upperBound) == true, String.Format("1-dimensional Integrator {0} does not support individual lower/upper bounds", numericalIntegrator.Factory.Name.String));

            numericalIntegrator.FunctionToIntegrate = x => 3.0 * x * x * x;

            double a        = 1.0; // see §21.5.25 in "Taschenbuch der Mathematik", Bronstein, Semendjajew, Musiol, Mühlig, 1995
            double expected = 3.0 / 5.0 * Math.Sqrt(Math.Pow(a * a - upperBound * upperBound, 5)) - a * a * Math.Sqrt(Math.Pow(a * a - upperBound * upperBound, 3)) - 3.0 / 5.0 * Math.Sqrt(Math.Pow(a * a - lowerBound * lowerBound, 5)) - a * a * Math.Sqrt(Math.Pow(a * a - lowerBound * lowerBound, 3));

            double actual;

            OneDimNumericalIntegrator.State state = numericalIntegrator.GetValue(out actual);

            Assert.That(actual, Is.EqualTo(expected).Within(1E-6), String.Format("1-dimensional integrator {0}; state: {1}.", numericalIntegrator.Factory.Name, state.ToString()));
        }
Esempio n. 2
0
        public void GetValue_OneOverWeightfunction_BenchmarkResult(
            [Values(10, 25, 50, 100)]
            int initialOrder,
            [Values(5, 10, 25)]
            int orderStepSize)
        {
            var gaussTschebyscheffIntegrator = new GaussTschebyscheffIntegrator(initialOrder, orderStepSize);
            var numericalIntegrator          = gaussTschebyscheffIntegrator.Create();

            double lowerBound = -1.0;
            double upperBound = 1.0;

            Assert.That(numericalIntegrator.TrySetBounds(lowerBound, upperBound) == true, String.Format("1-dimensional Integrator {0} does not support individual lower/upper bounds", numericalIntegrator.Factory.Name.String));

            numericalIntegrator.FunctionToIntegrate = x => Math.Sqrt(1.0 - x * x);  // for Tschebyscheff Integrator, the integrator is 1 in this case!

            double expected = upperBound - lowerBound;
            double actual   = numericalIntegrator.GetValue();

            Assert.That(actual, Is.EqualTo(expected).Within(1E-4), String.Format("1-dimensional integrator {0}.", numericalIntegrator.Factory.Name));
        }
Esempio n. 3
0
        public void GetValueWithState_OneOverWeightfunction_BenchmarkResult(
            [Values(10, 25, 50, 100)]
            int initialOrder,
            [Values(5, 10, 25)]
            int orderStepSize,
            [Values(-1.0, 2.5)]
            double lowerBound,
            [Values(1.0, 6.4)]
            double upperBound)
        {
            var gaussTschebyscheffIntegrator = new GaussTschebyscheffIntegrator(initialOrder, orderStepSize);
            var numericalIntegrator          = gaussTschebyscheffIntegrator.Create();

            Assert.That(numericalIntegrator.TrySetBounds(lowerBound, upperBound) == true, String.Format("1-dimensional Integrator {0} does not support individual lower/upper bounds", numericalIntegrator.Factory.Name.String));

            numericalIntegrator.FunctionToIntegrate = x => 1.0 / numericalIntegrator.WeightFunction.GetValue(x);

            double expected = upperBound - lowerBound;
            double actual;

            OneDimNumericalIntegrator.State state = numericalIntegrator.GetValue(out actual);

            Assert.That(actual, Is.EqualTo(expected).Within(1E-4), String.Format("1-dimensional integrator {0}; state: {1}.", numericalIntegrator.Factory.Name, state.ToString()));
        }
Esempio n. 4
0
 /// <summary>Initializes a new instance of the <see cref="Algorithm"/> class.
 /// </summary>
 /// <param name="gaussTschebyscheffIntegrator">The <see cref="GaussTschebyscheffIntegrator"/> object which serves as factory for the current object.</param>
 internal Algorithm(GaussTschebyscheffIntegrator gaussTschebyscheffIntegrator)
 {
     m_IntegratorFactory = gaussTschebyscheffIntegrator;
     WeightFunction      = OneDimNumericalIntegrator.WeightFunction.Create(x => 1.0 / Math.Sqrt(1.0 - x * x));
 }