001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.math4.legacy.analysis.solvers;
019
020/**
021 * Implements the <em>Regula Falsi</em> or <em>False position</em> method for
022 * root-finding (approximating a zero of a univariate real function). It is a
023 * modified {@link SecantSolver <em>Secant</em>} method.
024 *
025 * <p>The <em>Regula Falsi</em> method is included for completeness, for
026 * testing purposes, for educational purposes, for comparison to other
027 * algorithms, etc. It is however <strong>not</strong> intended to be used
028 * for actual problems, as one of the bounds often remains fixed, resulting
029 * in very slow convergence. Instead, one of the well-known modified
030 * <em>Regula Falsi</em> algorithms can be used ({@link IllinoisSolver
031 * <em>Illinois</em>} or {@link PegasusSolver <em>Pegasus</em>}). These two
032 * algorithms solve the fundamental issues of the original <em>Regula
033 * Falsi</em> algorithm, and greatly out-performs it for most, if not all,
034 * (practical) functions.
035 *
036 * <p>Unlike the <em>Secant</em> method, the <em>Regula Falsi</em> guarantees
037 * convergence, by maintaining a bracketed solution. Note however, that due to
038 * the finite/limited precision of Java's {@link Double double} type, which is
039 * used in this implementation, the algorithm may get stuck in a situation
040 * where it no longer makes any progress. Such cases are detected and result
041 * in a {@code ConvergenceException} exception being thrown. In other words,
042 * the algorithm theoretically guarantees convergence, but the implementation
043 * does not.</p>
044 *
045 * <p>The <em>Regula Falsi</em> method assumes that the function is continuous,
046 * but not necessarily smooth.</p>
047 *
048 * <p>Implementation based on the following article: M. Dowell and P. Jarratt,
049 * <em>A modified regula falsi method for computing the root of an
050 * equation</em>, BIT Numerical Mathematics, volume 11, number 2,
051 * pages 168-174, Springer, 1971.</p>
052 *
053 * @since 3.0
054 */
055public class RegulaFalsiSolver extends BaseSecantSolver {
056
057    /** Construct a solver with default accuracy (1e-6). */
058    public RegulaFalsiSolver() {
059        super(DEFAULT_ABSOLUTE_ACCURACY, Method.REGULA_FALSI);
060    }
061
062    /**
063     * Construct a solver.
064     *
065     * @param absoluteAccuracy Absolute accuracy.
066     */
067    public RegulaFalsiSolver(final double absoluteAccuracy) {
068        super(absoluteAccuracy, Method.REGULA_FALSI);
069    }
070
071    /**
072     * Construct a solver.
073     *
074     * @param relativeAccuracy Relative accuracy.
075     * @param absoluteAccuracy Absolute accuracy.
076     */
077    public RegulaFalsiSolver(final double relativeAccuracy,
078                             final double absoluteAccuracy) {
079        super(relativeAccuracy, absoluteAccuracy, Method.REGULA_FALSI);
080    }
081
082    /**
083     * Construct a solver.
084     *
085     * @param relativeAccuracy Relative accuracy.
086     * @param absoluteAccuracy Absolute accuracy.
087     * @param functionValueAccuracy Maximum function value error.
088     */
089    public RegulaFalsiSolver(final double relativeAccuracy,
090                             final double absoluteAccuracy,
091                             final double functionValueAccuracy) {
092        super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy, Method.REGULA_FALSI);
093    }
094}