View Javadoc
1   /*
2    * Copyright (C) 2023 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.irurueta.numerical.integration;
17  
18  import com.irurueta.numerical.SingleDimensionFunctionEvaluatorListener;
19  
20  /**
21   * Computes function integration by using Simpson's rule and trapezoidal quadrature.
22   * Simpson's method is an optimization of Trapezoidal quadrature integrator.
23   * Implementations of this class will in general be more efficient than
24   * Trapezoidal quadrature integrators (i.e., require fewer function evaluations) when the function
25   * to be integrated has a finite fourth derivative (i.e., a continuous third derivative).
26   * {@link SimpsonTrapezoidalQuadratureIntegrator} will in general be more efficient than
27   * {@link TrapezoidalQuadratureIntegrator} (i.e. require fewer function evaluations) when the
28   * function to be integrated has a finite fourth derivative (i.e. a continuous third derivative,
29   * which means that the function is sufficiently smooth).
30   */
31  public class SimpsonTrapezoidalQuadratureIntegrator extends SimpsonIntegrator<TrapezoidalQuadrature> {
32  
33      /**
34       * Constructor.
35       *
36       * @param a        Lower limit of integration.
37       * @param b        Upper limit of integration.
38       * @param listener listener to evaluate a single dimension function at required points.
39       * @param eps      required accuracy.
40       */
41      public SimpsonTrapezoidalQuadratureIntegrator(
42              final double a, final double b, final SingleDimensionFunctionEvaluatorListener listener, final double eps) {
43          super(new TrapezoidalQuadrature(a, b, listener), eps);
44      }
45  
46      /**
47       * Constructor with default accuracy.
48       *
49       * @param a Lower limit of integration.
50       * @param b Upper limit of integration.
51       * @param listener listener to evaluate a single dimension function at required points.
52       */
53      public SimpsonTrapezoidalQuadratureIntegrator(
54              final double a, final double b, final SingleDimensionFunctionEvaluatorListener listener) {
55          this(a, b, listener, EPS);
56      }
57  
58      /**
59       * Gets type of quadrature.
60       *
61       * @return type of quadrature.
62       */
63      @Override
64      public QuadratureType getQuadratureType() {
65          return QuadratureType.TRAPEZOIDAL;
66      }
67  }