Skip to main content
Mathematics LibreTexts

1.12: Roundoff Error Example

  • Page ID
    96038
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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 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; a detailed edit history is available upon request.