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