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.EvaluationException;
19  import com.irurueta.numerical.SingleDimensionFunctionEvaluatorListener;
20  
21  /**
22   * This is an exact replacement for MidPointQuadrature, except that it allows for an inverse
23   * square-root singularity in the integrand at the lower limit "a".
24   */
25  public class LowerSquareRootMidPointQuadrature extends MidPointQuadrature {
26  
27      /**
28       * Original lower bound of integration.
29       */
30      private final double aOrig;
31  
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 function at required points.
38       */
39      public LowerSquareRootMidPointQuadrature(
40              final double a, final double b, final SingleDimensionFunctionEvaluatorListener listener) {
41          super(0.0, Math.sqrt(b - a), listener);
42          aOrig = a;
43      }
44  
45      /**
46       * Gets type of quadrature.
47       *
48       * @return type of quadrature.
49       */
50      @Override
51      public QuadratureType getType() {
52          return QuadratureType.LOWER_SQUARE_ROOT_MID_POINT;
53      }
54  
55      /**
56       * Evaluates function at 2*x*f(a0+x^2).
57       *
58       * @param x point where function is evaluated.
59       * @return result of evaluation.
60       * @throws EvaluationException if evaluation fails.
61       */
62      @Override
63      protected double func(final double x) throws EvaluationException {
64          return 2.0 * x * listener.evaluate(aOrig + x * x);
65      }
66  }