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