RegulaFalsiSolver.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>Regula Falsi</em> or <em>False position</em> method for
  24.  * root-finding (approximating a zero of a univariate real function). It is a
  25.  * modified {@link SecantSolver <em>Secant</em>} method.
  26.  *
  27.  * <p>The <em>Regula Falsi</em> method is included for completeness, for
  28.  * testing purposes, for educational purposes, for comparison to other
  29.  * algorithms, etc. It is however <strong>not</strong> intended to be used
  30.  * for actual problems, as one of the bounds often remains fixed, resulting
  31.  * in very slow convergence. Instead, one of the well-known modified
  32.  * <em>Regula Falsi</em> algorithms can be used ({@link IllinoisSolver
  33.  * <em>Illinois</em>} or {@link PegasusSolver <em>Pegasus</em>}). These two
  34.  * algorithms solve the fundamental issues of the original <em>Regula
  35.  * Falsi</em> algorithm, and greatly out-performs it for most, if not all,
  36.  * (practical) functions.
  37.  *
  38.  * <p>Unlike the <em>Secant</em> method, the <em>Regula Falsi</em> guarantees
  39.  * convergence, by maintaining a bracketed solution. Note however, that due to
  40.  * the finite/limited precision of Java's {@link Double double} type, which is
  41.  * used in this implementation, the algorithm may get stuck in a situation
  42.  * where it no longer makes any progress. Such cases are detected and result
  43.  * in a {@code MathIllegalStateException} exception being thrown. In other words,
  44.  * the algorithm theoretically guarantees convergence, but the implementation
  45.  * does not.</p>
  46.  *
  47.  * <p>The <em>Regula Falsi</em> method assumes that the function is continuous,
  48.  * but not necessarily smooth.</p>
  49.  *
  50.  * <p>Implementation based on the following article: M. Dowell and P. Jarratt,
  51.  * <em>A modified regula falsi method for computing the root of an
  52.  * equation</em>, BIT Numerical Mathematics, volume 11, number 2,
  53.  * pages 168-174, Springer, 1971.</p>
  54.  *
  55.  */
  56. public class RegulaFalsiSolver extends BaseSecantSolver {

  57.     /** Construct a solver with default accuracy (1e-6). */
  58.     public RegulaFalsiSolver() {
  59.         super(DEFAULT_ABSOLUTE_ACCURACY, Method.REGULA_FALSI);
  60.     }

  61.     /**
  62.      * Construct a solver.
  63.      *
  64.      * @param absoluteAccuracy Absolute accuracy.
  65.      */
  66.     public RegulaFalsiSolver(final double absoluteAccuracy) {
  67.         super(absoluteAccuracy, Method.REGULA_FALSI);
  68.     }

  69.     /**
  70.      * Construct a solver.
  71.      *
  72.      * @param relativeAccuracy Relative accuracy.
  73.      * @param absoluteAccuracy Absolute accuracy.
  74.      */
  75.     public RegulaFalsiSolver(final double relativeAccuracy,
  76.                              final double absoluteAccuracy) {
  77.         super(relativeAccuracy, absoluteAccuracy, Method.REGULA_FALSI);
  78.     }

  79.     /**
  80.      * Construct a solver.
  81.      *
  82.      * @param relativeAccuracy Relative accuracy.
  83.      * @param absoluteAccuracy Absolute accuracy.
  84.      * @param functionValueAccuracy Maximum function value error.
  85.      */
  86.     public RegulaFalsiSolver(final double relativeAccuracy,
  87.                              final double absoluteAccuracy,
  88.                              final double functionValueAccuracy) {
  89.         super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy, Method.REGULA_FALSI);
  90.     }
  91. }