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 i.e., returns the nth stage of refinement of
23   * the integral of a function from "a" to "b", except that the function is evaluated at evenly spaced
24   * points in 1=x rather than in x. This allows the upper limit "b" to be as large and positive as the
25   * computer allows, or the lower limit "a" to be as large and negative, but not both. "a" and "b" must
26   * have the same sign.
27   */
28  public class InfinityMidPointQuadrature extends MidPointQuadrature {
29      /**
30       * Constructor.
31       *
32       * @param a        Lower limit of integration.
33       * @param b        Upper limit of integration.
34       * @param listener listener to evaluate a single dimension function at required points.
35       */
36      public InfinityMidPointQuadrature(
37              final double a, final double b, final SingleDimensionFunctionEvaluatorListener listener) {
38          super(1.0 / b, 1.0 / a, listener);
39      }
40  
41      /**
42       * Gets type of quadrature.
43       *
44       * @return type of quadrature.
45       */
46      @Override
47      public QuadratureType getType() {
48          return QuadratureType.INFINITY_MID_POINT;
49      }
50  
51      /**
52       * Evaluates function at 1/x.
53       *
54       * @param x point where function is evaluated.
55       * @return result of evaluation.
56       * @throws EvaluationException if evaluation fails.
57       */
58      @Override
59      protected double func(final double x) throws EvaluationException {
60          return listener.evaluate(1.0 / x) / (x * x);
61      }
62  }