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 upper limit is assumed to be 24 * infinite. It is assumed that the function decreases exponentially rapidly at infinity. 25 */ 26 public class ExponentialMidPointMatrixQuadrature extends MidPointMatrixQuadrature { 27 28 /** 29 * Constructor. 30 * 31 * @param a Lower limit of integration. 32 * @param listener listener to evaluate a single dimension function at required points. 33 * @throws WrongSizeException if size notified by provided listener is invalid. 34 */ 35 public ExponentialMidPointMatrixQuadrature( 36 final double a, final MatrixSingleDimensionFunctionEvaluatorListener listener) throws WrongSizeException { 37 super(0.0, Math.exp(-a), listener); 38 } 39 40 /** 41 * Gets type of quadrature. 42 * 43 * @return type of quadrature. 44 */ 45 @Override 46 public QuadratureType getType() { 47 return QuadratureType.EXPONENTIAL_MID_POINT; 48 } 49 50 /** 51 * Evaluates function at f(-log(x))/x. 52 * 53 * @param x point where function is evaluated. 54 * @param result instance where result of evaluation is stored. 55 * @throws EvaluationException if evaluation fails. 56 */ 57 @Override 58 protected void func(final double x, final Matrix result) throws EvaluationException { 59 listener.evaluate(-Math.log(x), result); 60 result.multiplyByScalar(1.0 / x); 61 } 62 }