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
18 package org.apache.commons.math4.legacy.analysis.solvers;
19
20 /**
21 * Implements the <em>Regula Falsi</em> or <em>False position</em> method for
22 * root-finding (approximating a zero of a univariate real function). It is a
23 * modified {@link SecantSolver <em>Secant</em>} method.
24 *
25 * <p>The <em>Regula Falsi</em> method is included for completeness, for
26 * testing purposes, for educational purposes, for comparison to other
27 * algorithms, etc. It is however <strong>not</strong> intended to be used
28 * for actual problems, as one of the bounds often remains fixed, resulting
29 * in very slow convergence. Instead, one of the well-known modified
30 * <em>Regula Falsi</em> algorithms can be used ({@link IllinoisSolver
31 * <em>Illinois</em>} or {@link PegasusSolver <em>Pegasus</em>}). These two
32 * algorithms solve the fundamental issues of the original <em>Regula
33 * Falsi</em> algorithm, and greatly out-performs it for most, if not all,
34 * (practical) functions.
35 *
36 * <p>Unlike the <em>Secant</em> method, the <em>Regula Falsi</em> guarantees
37 * convergence, by maintaining a bracketed solution. Note however, that due to
38 * the finite/limited precision of Java's {@link Double double} type, which is
39 * used in this implementation, the algorithm may get stuck in a situation
40 * where it no longer makes any progress. Such cases are detected and result
41 * in a {@code ConvergenceException} exception being thrown. In other words,
42 * the algorithm theoretically guarantees convergence, but the implementation
43 * does not.</p>
44 *
45 * <p>The <em>Regula Falsi</em> method assumes that the function is continuous,
46 * but not necessarily smooth.</p>
47 *
48 * <p>Implementation based on the following article: M. Dowell and P. Jarratt,
49 * <em>A modified regula falsi method for computing the root of an
50 * equation</em>, BIT Numerical Mathematics, volume 11, number 2,
51 * pages 168-174, Springer, 1971.</p>
52 *
53 * @since 3.0
54 */
55 public class RegulaFalsiSolver extends BaseSecantSolver {
56
57 /** Construct a solver with default accuracy (1e-6). */
58 public RegulaFalsiSolver() {
59 super(DEFAULT_ABSOLUTE_ACCURACY, Method.REGULA_FALSI);
60 }
61
62 /**
63 * Construct a solver.
64 *
65 * @param absoluteAccuracy Absolute accuracy.
66 */
67 public RegulaFalsiSolver(final double absoluteAccuracy) {
68 super(absoluteAccuracy, Method.REGULA_FALSI);
69 }
70
71 /**
72 * Construct a solver.
73 *
74 * @param relativeAccuracy Relative accuracy.
75 * @param absoluteAccuracy Absolute accuracy.
76 */
77 public RegulaFalsiSolver(final double relativeAccuracy,
78 final double absoluteAccuracy) {
79 super(relativeAccuracy, absoluteAccuracy, Method.REGULA_FALSI);
80 }
81
82 /**
83 * Construct a solver.
84 *
85 * @param relativeAccuracy Relative accuracy.
86 * @param absoluteAccuracy Absolute accuracy.
87 * @param functionValueAccuracy Maximum function value error.
88 */
89 public RegulaFalsiSolver(final double relativeAccuracy,
90 final double absoluteAccuracy,
91 final double functionValueAccuracy) {
92 super(relativeAccuracy, absoluteAccuracy, functionValueAccuracy, Method.REGULA_FALSI);
93 }
94 }