1.12: Roundoff Error Example

Numerical Methods · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY 3.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    1.12: Roundoff Error Example

    Consider solving the quadratic equation

    \[x^{2}+2 b x-1=0 \nonumber \]

    where \(b\) is a parameter. The quadratic formula yields the two solutions

    \[x_{\pm}=-b \pm \sqrt{b^{2}+1} \nonumber \]

    Consider the solution with \(b>0\) and \(x>0\) (the \(x_{+}\)solution) given by

    \[x=-b+\sqrt{b^{2}+1} \nonumber \]

    As \(b \rightarrow \infty\)

    \[\begin{aligned} x &=-b+\sqrt{b^{2}+1} \\ &=-b+b \sqrt{1+1 / b^{2}} \\ &=b\left(\sqrt{1+1 / b^{2}}-1\right) \\ & \approx b\left(1+\frac{1}{2 b^{2}}-1\right) \\ &=\frac{1}{2 b} . \end{aligned} \nonumber \]

    Now in double precision, realmin \(\approx 2.2 \times 10^{-308}\) and we would like \(x\) to be accurate to this value before it goes to 0 via denormal numbers. Therefore, \(x\) should be computed accurately to \(b \approx 1 /(2 \times\) realmin \() \approx 2 \times 10^{307}\). What happens if we compute (1.1) directly? Then \(x=0\) when \(b^{2}+1=b^{2}\), or \(1+1 / b^{2}=1 .\) That is \(1 / b^{2}=\epsilon_{\text {mach }} / 2\), or \(b=\sqrt{2} / \sqrt{\epsilon_{\text {mach }}} \approx 10^{8} .\) For a subroutine written to compute the solution of a quadratic for a general user, this is not good enough. The way for a software designer to solve this problem is to compute the solution for \(x\) as

    \[x=\frac{1}{b\left(1+\sqrt{1+1 / b^{2}}\right)} \nonumber \]

    In this form, if \(1+1 / b^{2}=1\), then \(x=1 / 2 b\) which is the correct asymptotic form.


    This page titled 1.12: Roundoff Error Example was last modified on Tue, 31 May 2022 08:21:31 GMT and is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Jeffrey R. Chasnov via source content that was edited to the style and standards of the LibreTexts platform.