Professional Documents
Culture Documents
b. Check that for a sufficiently small value of 𝑥, your algorithm converges to the correct
answer.
c. Compare the number of decimal places of precision obtained with that expected
𝑡ℎ
𝑛 𝑡𝑒𝑟𝑚
from the convergence criterion: | 𝑠𝑢𝑚
| < ϵ.
d. Explore that without using the identity sin(𝑥 + 2𝑛π) = sin(𝑥), there is a range of
somewhat large values of 𝑥 for which the algorithm converges to the wrong answer!
e. Further, explore that if you keep increasing the input argument 𝑥, the algorithm does
not even converge!
f. For the same values of input 𝑥 in the last two parts, now use the identity
sin(𝑥 + 2𝑛π) = sin(𝑥) to recalculate the values sin(𝑥).
g. Set your tolerance to a number smaller than the machine precision and see how it
affects your conclusions
b. Comment on the ratio ϵ𝑥/𝑥 for each of these numbers 𝑥. Does this give you
a clue as to why we expressed the ‘approximate’ computer representation of
a number 𝑎 ≃ 𝑎 ( 1 + ϵ𝑎). (This was asked by a student in class). Write
down your observations and comments.
3. Reading: Landau, Paez and Bordeianu 3.1.1 (Numerical errors from Subtractive
cancellation)
2
Consider the quadratic equation 𝑎 𝑥 + 𝑏𝑥 + 𝑐 = 0 which has an analytic solution
that can be written in one of the following two ways:
2
−𝑏 ± 𝑏 −4𝑎𝑐
𝑥1, 2 = 2𝑎
or,
' −2𝑐
𝑥 = 2
1,2 𝑏 ± 𝑏 −4𝑎𝑐
Upon inspection, we find that subtractive cancellation leads to an increase in the
2
error of one of the roots when 𝑏 ≫ 4𝑎𝑐.
a. Write a program to calculate both pairs of solutions for arbitrary values of 𝑎, 𝑏,
and 𝑐.
4. Calculating the sum of a simple series may require some thought and care. Consider
the two series:
𝑁
(𝑢𝑝)
𝑆 = ∑ (1/𝑛) and,
𝑛=1
1
(𝑑𝑜𝑤𝑛)
𝑆 = ∑ (1/𝑛)
𝑛=𝑁
Both series are finite (as 𝑁 is finite), and when summed analytically both give the
(𝑢𝑝)
same answers. Nonetheless, the numerical value of 𝑆 will not be precisely that of
(𝑑𝑜𝑤𝑛)
𝑆 .
(𝑢𝑝) (𝑑𝑜𝑤𝑛)
a. Write a program to calculate 𝑆 and 𝑆 as a function of 𝑁.
c. Observe the linear regime on your graph and explain why the downward sum
is generally more precise?