Numerical Methods in Quantum Mechanics - Dipartimento di Fisica
Numerical Methods in Quantum Mechanics - Dipartimento di Fisica
Numerical Methods in Quantum Mechanics - Dipartimento di Fisica
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Appen<strong>di</strong>x E<br />
Useful algorithms<br />
E.1 Search of the zeros of a function<br />
Short notes on the problem of numerical determ<strong>in</strong>ation of the zeros of a function,<br />
i.e. the values of x that solve f(x) = 0 for a given function.<br />
There are two <strong>di</strong>fferent types of zeros:<br />
• odd – when f(x) changes sign at x 0<br />
• even – when f(x) does not change sign at x 0<br />
The latter case is more <strong>di</strong>fficult from a numerical po<strong>in</strong>t of view. Imag<strong>in</strong>e to<br />
add a small numerical noise to f(x): the zero <strong>di</strong>sappears, or else it splits <strong>in</strong>to<br />
two odd zeros. It is usually convenient to resort to methods to localize extrema<br />
(m<strong>in</strong>ima or maxima) rather than try<strong>in</strong>g to p<strong>in</strong>po<strong>in</strong>t the zero. In the follow<strong>in</strong>g<br />
we will deal with odd zeros only.<br />
E.1.1<br />
Bisection method<br />
We first have to f<strong>in</strong>d an <strong>in</strong>terval [a, b] that <strong>in</strong>cludes a s<strong>in</strong>gle zero, <strong>in</strong> such a way<br />
that f(a)f(b) < 0. The bisection algorithm halves the <strong>in</strong>terval at each iteration,<br />
by ref<strong>in</strong><strong>in</strong>g the estimate of x 0 :<br />
1. c = (a + b)/2<br />
2. if f(a)f(c) < 0 we re-def<strong>in</strong>e b = c; else if f(b)f(c) < 0 we re-def<strong>in</strong>e a = c.<br />
3. In this way we get a new <strong>in</strong>terval [a, b] of half the width at the previous<br />
step, and we repeat the procedure.<br />
Convergence is guaranteed (it is impossible to ”miss” the zero), and the logarithm<br />
of the uncerta<strong>in</strong>ty on the solution l<strong>in</strong>early decreases with the number of<br />
iterations. Some <strong>di</strong>fficulty may arise <strong>in</strong> the choice of the stopp<strong>in</strong>g criterion. For<br />
<strong>in</strong>stance:<br />
• Absolute error: |a − b| < ɛ. This may run <strong>in</strong>to trouble if x 0 is very large:<br />
round<strong>in</strong>g errors |a − b| might be larger then ɛ.<br />
96