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 19 import com.irurueta.numerical.SingleDimensionFunctionEvaluatorListener; 20 21 /** 22 * Computes function integration by using Simpson's rule and mid-point quadrature. 23 * Simpson's method is an optimization of Trapezoidal quadrature integrator. 24 * This type of integrator will in general be more efficient than Trapezoidal quadrature 25 * integrators (i.e., require fewer function evaluations) when the function 26 * to be integrated has a finite fourth derivative (i.e., a continuous third derivative). 27 */ 28 public class SimpsonMidPointQuadratureIntegrator extends SimpsonIntegrator<MidPointQuadrature> { 29 30 /** 31 * Constructor. 32 * 33 * @param a Lower limit of integration. 34 * @param b Upper limit of integration. 35 * @param listener listener to evaluate a single dimension function at required points. 36 * @param eps required accuracy. 37 */ 38 public SimpsonMidPointQuadratureIntegrator( 39 final double a, final double b, final SingleDimensionFunctionEvaluatorListener listener, final double eps) { 40 super(new MidPointQuadrature(a, b, listener), eps); 41 } 42 43 /** 44 * Constructor. 45 * 46 * @param a Lower limit of integration. 47 * @param b Upper limit of integration. 48 * @param listener listener to evaluate a single dimension function at required points. 49 */ 50 public SimpsonMidPointQuadratureIntegrator( 51 final double a, final double b, final SingleDimensionFunctionEvaluatorListener listener) { 52 this(a, b, listener, EPS); 53 } 54 55 /** 56 * Gets type of quadrature. 57 * 58 * @return type of quadrature. 59 */ 60 @Override 61 public QuadratureType getQuadratureType() { 62 return QuadratureType.MID_POINT; 63 } 64 }