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

Verified
Answer
Question: Show that \(f_1(x, \delta) / \delta\) and \(f_2(x, \delta) / \delta\) are effective approximations of \(-\sin(x)\) for small \(\delta\), and explain the difference in results of \(g_1(x, \delta)\) and \(g_2(x, \delta)\) for \(x = 3\) and \(\delta = 1e-11\). Answer: Both \(f_1(x, \delta) / \delta\) and \(f_2(x, \delta) / \delta\) can effectively approximate \(-\sin(x)\) for small values of \(\delta\), as shown analytically. The difference in results of \(g_1(x, \delta)\) and \(g_2(x, \delta)\) arises from the limited precision of floating-point numbers in MATLAB. When \(\delta\) is very small, calculations involving \(f_1(x, \delta)\) suffer from catastrophic cancellation due to the subtraction of nearly equal numbers, resulting in a loss of precision. Conversely, \(f_2(x, \delta)\) does not involve such subtraction and provides more accurate results for small values of \(\delta\).
1Step 1: (a) Showing effective approximation
Analytically, we want to show that \(f_1(x, \delta) / \delta\) and \(f_2(x, \delta) / \delta\) are effective approximations of \(-\sin(x)\) for \(\delta\) sufficiently small. Consider the function \(f_1(x, \delta)\), $$ f_1(x, \delta) = \cos(x+\delta) - \cos(x). $$ Now divide by \(\delta\): $$ \frac{f_1(x, \delta)}{\delta} = \frac{\cos(x+\delta) - \cos(x)}{\delta}. $$ As \(\delta \to 0\), the expression on the right side becomes the derivative of \(\cos(x)\) with respect to \(x\): $$ \lim_{\delta \to 0} \frac{\cos(x+\delta) - \cos(x)}{\delta} = -\sin(x). $$ So, \(f_1(x, \delta) / \delta\) can effectively approximate \(-\sin(x)\) for small values of \(\delta\). The same analysis applies to \(f_2(x, \delta)\).
2Step 2: (b) Deriving \(f_2(x, \delta)\)
Now we will derive \(f_2(x, \delta)\) by substituting \(\phi = x+\delta\) and \(\psi = x\) into the trigonometric formula: $$ \cos(\phi) - \cos(\psi) = -2 \sin\left(\frac{\phi+\psi}{2}\right) \sin\left(\frac{\phi-\psi}{2}\right). $$ Plugging in \(\phi = x+\delta\) and \(\psi = x\), we get: $$ f_2(x, \delta) = -2 \sin\left(\frac{x + \delta + x}{2}\right) \sin\left(\frac{x + \delta - x}{2}\right). $$ Simplify the expression: $$ f_2(x, \delta) = -2 \sin\left(\frac{2x + \delta}{2}\right) \sin\left(\frac{\delta}{2}\right) = -2 \sin(x + \frac{\delta}{2}) \sin\left(\frac{\delta}{2}\right). $$
3Step 3: (c) MATLAB script
Here is the requested MATLAB script to calculate \(g_1(x, \delta)\) and \(g_2(x, \delta)\) for \(x = 3\) and \(\delta = 1e-11\): ```MATLAB x = 3; delta = 1e-11; % Calculate f1(x, delta) and f2(x, delta) f1 = cos(x + delta) - cos(x); f2 = -2 * sin(x + delta / 2) * sin(delta / 2); % Calculate g1(x, delta) and g2(x, delta) g1 = f1 / delta + sin(x); g2 = f2 / delta + sin(x); % Display the results disp(['g1(x, delta) = ', num2str(g1)]); disp(['g2(x, delta) = ', num2str(g2)]); ```
4Step 4: (d) Explaining difference in results
The difference in the results of the two calculations can be attributed to the limited precision of floating-point numbers in MATLAB. When \(\delta\) is very small, the calculations involving \(f_1(x, \delta)\) can suffer from catastrophic cancellation due to the subtraction of nearly equal numbers, leading to a loss of precision. On the other hand, \(f_2(x, \delta)\) does not involve such subtraction, so its results tend to be more accurate for small values of \(\delta\).

Key Concepts

Trigonometric IdentitiesFloating Point PrecisionCatastrophic Cancellation
Trigonometric Identities
Trigonometric identities are mathematical relationships involving trigonometric functions like sine, cosine, and tangent. These identities allow us to simplify expressions and solve equations involving these functions. A key identity used in this exercise is:
  • \( \cos(\phi) - \cos(\psi) = -2 \sin\left(\frac{\phi+\psi}{2}\right) \sin\left(\frac{\phi-\psi}{2}\right) \).
This identity transforms the difference of two cosines into a product of sines.
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
Floating point numbers are used in computers to represent real numbers. They have a fixed precision determined by the number of bits used to store them. Floating point precision becomes crucial in calculations where very small or very large numbers are involved.

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)\).
Understanding and considering floating point precision is essential when writing programs or scripts that require high numerical accuracy. MATLAB, like other computing environments, provides functions and quirks that can mitigate these limitations.
Catastrophic Cancellation
Catastrophic cancellation occurs when subtracting two nearly equal numbers. It causes significant loss of precision because the significant digits cancel each other out, leaving behind only the insignificant ones.

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.
Recognizing when catastrophic cancellation might occur helps in choosing appropriate mathematical formulations to avoid significant computation errors. This highlights the importance of exploring multiple representations and understanding the underlying numerical algorithms in scientific computations.