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.  *      http://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. package org.apache.commons.math4.legacy.analysis.solvers;

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

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

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

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

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