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