Once bracketed, there are several classical ways of refining a root of a non-linear or non-analytical function. Among them, the most robust is the bissection (Press et al. (1992)). It always gives the correct answer if the root is correctly bracketed and if the function is continuous. However, it is not the quickest way in most of the situations. Like Herrmann (1994), we implemented an algorithm that mixes the bissection method and a Lagrange polynomial fit. The Lagrange polynomial is best constructed using the iterative Neville's algorithm (Press et al. (1992)). Corrections have been brought to Herrmann's algorithm to achieve better performances.
|
Practically, from the two initial bracketing values (
and
), a third point
is calculated by bissection.
to
are the values of
for
to
, respectively. According to the sign of
, either
or
is replaced by the value
, swapping them eventually afterwards to keep
. It is the state described by figure 3.6(a), where
and
are represented by black dots. A Lagrange polynomial is constructed on those two samples (a line in this case), shown by the thin plain line. From the intersection of the polynomial with axis
, a new
is deduced, it is shifted by a tenth of
towards the limit with the highest
value, and
is re-calculated. If
is located between
and
, the function is bijective inside
and hence invertible between
and
. This is not the case in figure 3.6(b). Consequently, the algorithm returns to bissection to generate a new sample
from the current
and
. As in the first step, either
or
is replaced by the value
(new brackets are shown in figure 3.6(c) by black dots). New samples (grey dots) are generated from the polynomial fit and integrated into it. In figures 3.6(d) to 3.6(f), the degree increases at each step as new samples are added.
To efficiently calculate the root of a Lagrange polynomial
, the axis X and Y are swapped during its construction. The coordinates of the samples are swapped so that
fits
,
, .... The current estimate for the root is
. If
and
differ from a factor 10 or more, the Neville's algorithm may fail and it is better to return to the bissection until reducing the ratio. To avoid a quick return to bissection, the newly generated point has to be on the side of the true root where either
or
is maximum. For doing so, the calculated value is considered as the true root, and it is shifted by a tenth of the current bracket interval towards the boundary having the highest value for the function. In most cases, when the true function is locally weakly non-linear, the limit with the highest function value is replaced by the new shifted estimate of the root at the next iteration, keeping the order of magnitude of
and
in the same range. This is the minor modification we brought to Herrmann's algorithm (1994), but it has a major influence over the global performances, as the full power of the polynomial fit is used. The maximum degree of the polynomial is set to 19, because its coefficients are stored in a static vector of limited length for efficiency. In a contradictory way, finding the perfect root 3.3 is a problem because the inferior and superior brackets are lost as no sign can indicate on which side of the true root a new sample is. It may ruin the root search for the next modes. This case is checked, and the computation of the function is redone at a slightly distinct value (minus one tenth of the current bracketed interval).
With this method, only 4 to 6 iterations are generally necessary to obtain a
relative precision. One iteration corresponds to one evaluation of the numerical function
. In the original code written by Herrmann (1994), the degree of the polynomial never increases over 2 or 3, quickly returning to bissection. More than 10 iterations are necessary to achieve the same precision. Our code rarely returns to bissection, increasing the degree of the polynomial at each iteration. Together with the removal of all file Input/Output, it has been possible to drop the time consumption by a factor 5 to 6.