Problem 10
Question
The function \(f_{1}(x, \delta)=\cos (x+\delta)-\cos (x)\) can be transformed into another form, \(f_{2}(x, \delta)\), using the trigonometric formula $$ \cos (\phi)-\cos (\psi)=-2 \sin \left(\frac{\phi+\psi}{2}\right) \sin \left(\frac{\phi-\psi}{2}\right) . $$ Thus, \(f_{1}\) and \(f_{2}\) have the same values, in exact arithmetic, for any given argument values \(x\) and \(\delta\). (a) Show that, analytically, \(f_{1}(x, \delta) / \delta\) or \(f_{2}(x, \delta) / \delta\) are effective approximations of the function \(-\sin (x)\) for \(\delta\) sufficiently small. (b) Derive \(f_{2}(x, \delta)\). (c) Write a MATLAB script which will calculate \(g_{1}(x, \delta)=f_{1}(x, \delta) / \delta+\sin (x)\) and \(g_{2}(x, \delta)=\) \(f_{2}(x, \delta) / \delta+\sin (x)\) for \(x=3\) and \(\delta=1 . \mathrm{e}-11 .\) (d) Explain the difference in the results of the two calculations.
Step-by-Step Solution
VerifiedKey Concepts
Trigonometric Identities
- \( \cos(\phi) - \cos(\psi) = -2 \sin\left(\frac{\phi+\psi}{2}\right) \sin\left(\frac{\phi-\psi}{2}\right) \).
In this particular problem, it helps in deriving the expression for \(f_2(x, \delta)\) from \(f_1(x, \delta)\) by substituting \(\phi = x + \delta\) and \(\psi = x\). This transformation makes the function easier to analyze, especially when using it for numerical computations.
Floating Point Precision
In our problem, we deal with very small \(\delta\). When calculating using formulas like \(f_1(x, \delta) = \cos(x+\delta) - \cos(x)\), the limited precision of floating point numbers can affect the accuracy of results.
- Small changes in values can be lost due to rounding errors.
- Precision error increases when small differences of large numbers are computed, i.e., \(\cos(x+\delta) - \cos(x)\).
Catastrophic Cancellation
This is particularly relevant in the exercise at hand. Calculating \(f_1(x, \delta)\) involves subtracting two similar cosine values, especially for small \(\delta\). This subtraction can lead to catastrophic cancellation, creating inaccurate results.
- The subtraction in \(f_1(x, \delta)\) leads to a precision loss since \(\delta\) is very small.
- The alternate formulation, \(f_2(x, \delta)\), avoids direct subtraction of similar values, thus providing a more stable and accurate result.