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