All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opengamma.strata.math.impl.integration.IntegratorRepeated2D Maven / Gradle / Ivy

There is a newer version: 2.12.46
Show newest version
/*
 * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.strata.math.impl.integration;

import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * Two dimensional integration by repeated one dimensional integration using {@link Integrator1D}.
 */
public class IntegratorRepeated2D
    extends Integrator2D {

  /**
   * The 1-D integrator to be used for each repeated integral.
   */
  private final Integrator1D _integrator1D;

  /**
   * Constructor.
   * 
   * @param integrator1D  the 1-D integrator to be used for each repeated integral
   */
  public IntegratorRepeated2D(Integrator1D integrator1D) {
    _integrator1D = integrator1D;
  }

  //-------------------------------------------------------------------------
  @Override
  public Double integrate(BiFunction f, Double[] lower, Double[] upper) {
    return _integrator1D.integrate(innerIntegral(f, lower[0], upper[0]), lower[1], upper[1]);
  }

  /**
   * The inner integral function of the repeated 1-D integrations.
   * For a given $y$ it returns $\int_{x_1}^{x_2} f(x,y) dx$.
   * 
   * @param f  the bi-function
   * @param lower  the lower bound (for the inner-first variable)
   * @param upper  the upper bound (for the inner-first variable)
   * @return the inner integral function
   */
  private Function innerIntegral(BiFunction f, Double lower, Double upper) {
    return y -> _integrator1D.integrate(x -> f.apply(x, y), lower, upper);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy