1.4 Practice Problems

Problem 1.4.1. Find the third Taylor polynomial \(P_3\) of \(f(x) = \ln (1+x)\) about \(x_0 = 0\), use it to approximate \(\ln 1.1\), and find a bound for the error. Compare it with the actual error.

Show solution

Solution. \(f'(x) = (1+x)^{-1}\), \(f''(x) = -(1+x)^{-2}\), \(f'''(x) = 2(1+x)^{-3}\), \(f^{(4)}(x) = -6(1+x)^{-4}\). So \(P_3(x) = x-\frac {x^2}{2}+\frac {x^3}{3}\) and \(P_3(0.1) = 0.1-0.005+0.000\overline {3} = 0.095\overline {3}\). The remainder is \(R_3(x) = -\frac {6}{(1+\xi )^4}\frac {x^4}{24}\) with \(0<\xi <0.1\), so \(|R_3(0.1)|\leq \frac {(0.1)^4}{4} = 2.5\times 10^{-5}\). Since \(\ln 1.1 = 0.0953102\), the actual error is \(2.3\times 10^{-5}\): the bound is nearly sharp, because \(\xi \) is close to \(0\).

Problem 1.4.2. Use four-digit rounding arithmetic to compute \(\frac {13}{14}-\frac 67\) and \(\left (\frac {13}{14}-\frac 67\right )/(2e-5.4)\), and find the relative errors.

Show solution

Solution. \(\fl \left (\frac {13}{14}\right ) = 0.9286\) and \(\fl \left (\frac 67\right ) = 0.8571\), so the difference is \(0.07150\); the true value is \(\frac 1{14} = 0.0714286\), a relative error of \(1.0\times 10^{-3}\). For the denominator, \(\fl (2e) = \fl (5.43656) = 5.437\) and \(5.437-5.4 = 0.03700\), while the true value is \(0.0365637\): relative error \(1.2\times 10^{-2}\), because the subtraction cancels three digits. The quotient is \(\fl (0.07150/0.03700) = 1.932\), against the true value \(1.953540\), a relative error of \(1.1\%\). Each subtraction of nearly equal numbers costs digits.

Problem 1.4.3. The function \(f(x) = \frac {1-\cos x}{x^2}\) tends to \(\frac 12\) as \(x\longrightarrow 0\). Explain why computing it directly for \(x = 10^{-5}\) in double precision gives a poor answer, and give an equivalent formula that does not.

Show solution

Solution. For small \(x\), \(\cos x\approx 1-\frac {x^2}{2}\) is very close to \(1\), so \(1-\cos x\) subtracts nearly equal numbers. At \(x = 10^{-5}\), \(1-\cos x\approx 5\times 10^{-11}\), while the absolute round-off error in \(\cos x\) is about \(10^{-16}\); the relative error of the difference can therefore be as large as \(10^{-16}/(5\times 10^{-11}) = 2\times 10^{-6}\). In fact double precision gives \(f(10^{-5}) = 0.50000004\), correct to only seven of its sixteen digits, and for \(x = 10^{-8}\) it gives \(0\), since \(\cos x\) rounds to exactly \(1\). Using \(1-\cos x = 2\sin ^2\frac {x}{2}\), \[f(x) = \frac {2\sin ^2(x/2)}{x^2} = \frac 12\left (\frac {\sin (x/2)}{x/2}\right )^2,\] which involves no subtraction and is accurate for all small \(x\).

Problem 1.4.4. Show that the \(k\)-digit rounding of \(\frac 23\) and of \(0.\overline {6}\) are the same, and find the smallest \(k\) for which \(\fl (\pi )\) (by rounding) approximates \(\pi \) with relative error less than \(10^{-6}\).

Show solution

Solution. They are the same number, \(0.666\ldots \); its \(k\)-digit rounding is \(0.66\ldots 67\) (with \(k-1\) sixes). For \(\pi \), Theorem 1.2.8 guarantees a relative error at most \(\frac 12\times 10^{1-k}\), which is below \(10^{-6}\) when \(k\geq 7\). In fact \(k = 6\) already works: \(\fl (\pi ) = 3.14159\) has relative error \(8.4\times 10^{-7}\). The theorem gives a guarantee for every number, not the error for a particular one.

Problem 1.4.5. Show that \(\frac {e^h-1}{h} = 1+O(h)\) as \(h\longrightarrow 0\), and find the rate of convergence of \(\frac {e^h-e^{-h}}{2h}\) to \(1\).

Show solution

Solution. By Taylor’s Theorem \(e^h = 1+h+\frac {h^2}{2}e^{\xi }\), so \(\frac {e^h-1}{h}-1 = \frac h2e^\xi \), which is at most \(\frac {e}{2}|h|\) for \(|h|\leq 1\): the rate is \(O(h)\). For the symmetric quotient, \(e^h-e^{-h} = 2h+\frac {h^3}{3}+\frac {h^5}{60}+\cdots \), so \(\frac {e^h-e^{-h}}{2h} = 1+\frac {h^2}{6}+O(h^4)\): the rate is \(O(h^2)\). This is the first sign of a fact used in numerical differentiation (Section 8.1): a centred difference is more accurate than a one-sided one.

Problem 1.4.6. A sequence satisfies \(p_n = p+\frac {1}{n}\). Show that it converges to \(p\) sublinearly, that is, \(\frac {|p_{n+1}-p|}{|p_n-p|}\longrightarrow 1\), and estimate how many terms are needed for an error below \(10^{-6}\). Contrast this with \(q_n = p+10^{-n}\).

Show solution

Solution. \(\frac {|p_{n+1}-p|}{|p_n-p|} = \frac {n}{n+1}\longrightarrow 1\), so the error ratio approaches \(1\) and each step gains less and less. An error below \(10^{-6}\) needs \(n>10^6\) terms. For \(q_n\) the ratio is exactly \(\frac {1}{10}\): linear convergence with \(\lambda = 0.1\), and seven terms suffice. Sublinear convergence is far too slow for practical use.

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.