You are on page 1of 7

Henry Ye, yeh3@rpi.

edu Homework 1: Numerical Computing


Problem 1.3
Part 1.3(a).
We know
ϵ ϵ ϵ
1− <1− <1−
2 3 4
Thus, 1 − ϵ/3 will get rounded to 1 − ϵ/2. So, the resulting difference evaluates

ϵ ϵ ϵ
(1 − ) − 1 ⇒ (1 − ) − 1 ⇒ −
3 2 2

Part 1.3(b).
We know
ϵ
1 − 2−55 = 1 −
8
Noting the inequality
ϵ ϵ ϵ
1− <1− <1+ ,
4 8 2
we find that 1 − 2−55 falls within the range that will get rounded to 1. Thus, the quantity in the
parentheses evaluates to 1, meaning the entire quantity evaluates to 0 .

Part 1.3(e).
Note that
ϵ ϵ ϵ
1− <1− <1+
4 8 2
and that
ϵ ϵ ϵ
1− <1+ <1+
4 3 2
meaning both the numerator and denominator will evaluate to 1. Thus, the quotient is 1 .
Problem 1.14.
The printed output was:
hour: 1.0100501613189776e+02
second: 1.0100501665618636e+02
millisecond: 1.0100495865961672e+02
nanosecond: 1.0000000000000000e+02
picosecond: 1.0000000000000000e+02

The values computed for nanoseconds and picoseconds is clearly incorrect. This occurs because for
sufficiently large n, the quantity 1 + r/n will be rounded to 1 in floating point, effectively making
the calculation 100(1)n = 100, which is the case for part nanoseconds and picoseconds.
Given r ∈ (0, 1), for 1 + r/n to incorrectly evaluate to 1, it must be that
ϵ r ϵ
1− <1+ <1+
4 n 2
Since we know r > 0 and n > 0, we can just look at the second inequality and simplify.
r ϵ
1+ <1+
n 2
r ϵ
<
n 2
2r
n>
ϵ
So, for r ∈ (0, 1), we would expect incorrect values to occur starting at

2r
n=
ϵ
Problem 1.16(f).
Using the geometric sequence formula, we simplify the sum and multiply the numerator and de-
nominator by a constant to prevent evaluation of excessively large numbers.

1 − e1001 e−500 − e501


= −500
1−e e − e−499
Taking the natural log of this yields

ln(e−500 − e501 ) − ln(e−500 − e−499 )

which is the formula used to compute as shown on the next page.

1.16(f) Extra Credit:


Using the geometric sum formula and exponentiating all terms, we have
( ) ( )
1000 e + 1 1 − e1001 1000 e
e < <e
e 1−e e−1
e+1 e −1000 −e e
< <
e 1−e e−1
Looking at the first inequality, we can simplify as follows:

e+1 e−1000 − e
<
e 1−e
(e − 1)(e + 1) < e − e−999
2

e2 − 1 < e2 − e−999
−1 < e−999

So, the first inequality holds. Looking at the second inequality, we have

e−1000 − e e
<
1−e e−1
e − e−1000 e
<
e−1 e−1
e − e−1000 < e
−e−1000 < 0

So, both inequalities hold and thus the original inequality holds.
( ) (1000 ) ( )
e+1 ∑ e
k
1000 + ln < ln e < 1000 + ln
e e−1
k=0
% ====== 1.16f
fprintf("\n\nQuestion 1.16f):\n\n%.16e\n", log(exp(-500) - exp(501)) -
log(exp(-500) - exp(-499)));

Question 1.16f):

1.0004586751453871e+03

Published with MATLAB® R2023a

1
Problem 1.21(b).
Intervals from 2 to 4 are of size 2ϵ and intervals from 4 to 8 are of size 4ϵ.
Thus, the numbers for which x will be rounded to 4 satisfy

4 − ϵ < x < 4 + 2ϵ
Problem 1.29.
Part 1.29(a).
The apparent limit is 0.002.

Part 1.29(b).
Note that sk − sk−1 = 0.63 · 10−(k+1) . Since 0.63 < 1, to find where iteration stops, we solve for
−(k + 1) = −8 which gives k = 7.
The number of significant digits is the number of digits between the 2 and 7, inclusive. This works
out to be k + 1 which means there are 8 correct significant digits at iteration k = 7.

Part 1.29(c).
Noting sk = 0.002 + 7 · 10−(k+3) , we have

|sk − sk−1 | 0.63 · 10−(k+1)


= < 10−8
|sk | 0.002 + 7 · 10−(k+3)
( )
0.63 · 10−(k+1) < 0.002 + 7 · 10−(k+3) 10−8
0.63 · 10−(k+1) < 0.002 · 10−8 + 7 · 10−11 · 10−k
( )
10−k 0.63 · 10−1 − 7 · 10−11 < 0.002 · 10−8
0.002 · 10−8
10−k <
(0.63 · 10−1 − 7 · 10−11 )
[ ]
−k = [log(0.002) − 8] − log(0.063 − 7 · 10−11 )
[ ]
= [log(2) − 11] − log(0.063 − 7 · 10−11 )

Note that log(0.063 − 7 · 10−11 ) > −2. Thus, we have

−k > [log(2) − 11] + 2 = log(2) − 9


−k > −9
k<9

So, iteration with relative error stops at k = 8, giving 9 correct significant digits.
Problem 6.
The largest n for which there was no error was 2.5 · 104 . My laptop has a 6-core CPU, 8 gigabytes
of DDR4 memory, and around 30 gigabytes of free space.
Note I have been running code using MATLAB Online since I had a bit of trouble installing the
MATLAB desktop application on my machine.

You might also like