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.algebra.WrongSizeException;
19  
20  /**
21   * Computes matrix 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 SimpsonTrapezoidalQuadratureMatrixIntegrator} will in general be more efficient than
27   * {@link TrapezoidalQuadratureMatrixIntegrator} (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 SimpsonTrapezoidalQuadratureMatrixIntegrator extends SimpsonMatrixIntegrator<TrapezoidalMatrixQuadrature> {
32      /**
33       * Constructor.
34       *
35       * @param a        Lower limit of integration.
36       * @param b        Upper limit of integration.
37       * @param listener listener to evaluate a single dimension matrix (multivariate) function at
38       *                 required points.
39       * @param eps      required accuracy.
40       * @throws WrongSizeException if size notified by provided listener is invalid.
41       */
42      public SimpsonTrapezoidalQuadratureMatrixIntegrator(
43              final double a, final double b, final MatrixSingleDimensionFunctionEvaluatorListener listener,
44              final double eps) throws WrongSizeException {
45          super(new TrapezoidalMatrixQuadrature(a, b, listener), eps);
46      }
47  
48      /**
49       * Constructor with default accuracy.
50       *
51       * @param a        Lower limit of integration.
52       * @param b        Upper limit of integration.
53       * @param listener listener to evaluate a single dimension function at required points.
54       * @throws WrongSizeException if size notified by provided listener is invalid.
55       */
56      public SimpsonTrapezoidalQuadratureMatrixIntegrator(
57              final double a, final double b, final MatrixSingleDimensionFunctionEvaluatorListener listener)
58              throws WrongSizeException {
59          this(a, b, listener, EPS);
60      }
61  
62      /**
63       * Gets type of quadrature.
64       *
65       * @return type of quadrature.
66       */
67      @Override
68      public QuadratureType getQuadratureType() {
69          return QuadratureType.TRAPEZOIDAL;
70      }
71  }