PegasusSolver.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. /*
  18.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */

  21. package org.hipparchus.analysis.solvers;

  22. /**
  23.  * Implements the <em>Pegasus</em> method for root-finding (approximating
  24.  * a zero of a univariate real function). It is a modified
  25.  * {@link RegulaFalsiSolver <em>Regula Falsi</em>} method.
  26.  *
  27.  * <p>Like the <em>Regula Falsi</em> method, convergence is guaranteed by
  28.  * maintaining a bracketed solution. The <em>Pegasus</em> method however,
  29.  * should converge much faster than the original <em>Regula Falsi</em>
  30.  * method. Furthermore, this implementation of the <em>Pegasus</em> method
  31.  * should not suffer from the same implementation issues as the <em>Regula
  32.  * Falsi</em> method, which may fail to convergence in certain cases. Also,
  33.  * the <em>Pegasus</em> method should converge faster than the
  34.  * {@link IllinoisSolver <em>Illinois</em>} method, another <em>Regula
  35.  * Falsi</em>-based method.</p>
  36.  *
  37.  * <p>The <em>Pegasus</em> method assumes that the function is continuous,
  38.  * but not necessarily smooth.</p>
  39.  *
  40.  * <p>Implementation based on the following article: M. Dowell and P. Jarratt,
  41.  * <em>The "Pegasus" method for computing the root of an equation</em>,
  42.  * BIT Numerical Mathematics, volume 12, number 4, pages 503-508, Springer,
  43.  * 1972.</p>
  44.  *
  45.  */
  46. public class PegasusSolver extends BaseSecantSolver {

  47.     /** Construct a solver with default accuracy (1e-6). */
  48.     public PegasusSolver() {
  49.         super(DEFAULT_ABSOLUTE_ACCURACY, Method.PEGASUS);
  50.     }

  51.     /**
  52.      * Construct a solver.
  53.      *
  54.      * @param absoluteAccuracy Absolute accuracy.
  55.      */
  56.     public PegasusSolver(final double absoluteAccuracy) {
  57.         super(absoluteAccuracy, Method.PEGASUS);
  58.     }

  59.     /**
  60.      * Construct a solver.
  61.      *
  62.      * @param relativeAccuracy Relative accuracy.
  63.      * @param absoluteAccuracy Absolute accuracy.
  64.      */
  65.     public PegasusSolver(final double relativeAccuracy,
  66.                          final double absoluteAccuracy) {
  67.         super(relativeAccuracy, absoluteAccuracy, Method.PEGASUS);
  68.     }

  69.     /**
  70.      * Construct a solver.
  71.      *
  72.      * @param relativeAccuracy Relative accuracy.
  73.      * @param absoluteAccuracy Absolute accuracy.
  74.      * @param functionValueAccuracy Maximum function value error.
  75.      */
  76.     public PegasusSolver(final double relativeAccuracy,
  77.                          final double absoluteAccuracy,
  78.                          final double functionValueAccuracy) {
  79.         super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy, Method.PEGASUS);
  80.     }
  81. }