../_images/book_cover.jpg

This notebook contains an excerpt from the Python Programming and Numerical Methods - A Guide for Engineers and Scientists, the content is also available at Berkeley Python Numerical Methods.

The copyright of the book belongs to Elsevier. We also have this interactive book online for a better learning experience. The code is released under the MIT license. If you find this content useful, please consider supporting the work on Elsevier or Amazon!

< 19.1 Root Finding Problem Statement | Contents | 19.3 Bisection Method >

Tolerance

In engineering and science, error is a deviation from an expected or computed value. Tolerance is the level of error that is acceptable for an engineering application. We say that a computer program has converged to a solution when it has found a solution with an error smaller than the tolerance. When computing roots numerically, or conducting any other kind of numerical analysis, it is important to establish both a metric for error and a tolerance that is suitable for a given engineering/science application.

For computing roots, we want an \(x_r\) such that \(f(x_r)\) is very close to 0. Therefore \(|f(x)|\) is a possible choice for the measure of error since the smaller it is, the likelier we are to a root. Also if we assume that \(x_i\) is the \(i\)th guess of an algorithm for finding a root, then \(|x_{i+1} - x_i|\) is another possible choice for measuring error, since we expect the improvements between subsequent guesses to diminish as it approaches a solution. As will be demonstrated in the following examples, these different choices have their advantages and disadvantages.

TRY IT! Let error be measured by \(e = |f(x)|\) and tol be the acceptable level of error. The function \(f(x) = x^2 + \text{tol}/2\) has no real roots. However, \(|f(0)| = {\text{tol}}/2\) and is therefore acceptable as a solution for a root finding program.

TRY IT! Let error be measured by \(e = |x_{i+1} - x_i|\) and tol be the acceptable level of error. The function \(f(x) = 1/x\) has no real roots, but the guesses \(x_i = -{\text{tol}}/4\) and \(x_{i+1} = {\text{tol}}/4\) have an error of \(e = {\text{tol}}/2\) and is an acceptable solution for a computer program.

Based on these observations, the use of tolerance and converging criteria must be done very carefully and in the context of the program that uses them.

< 19.1 Root Finding Problem Statement | Contents | 19.3 Bisection Method >