Due 23:59 Sunday, 2022-03-27
Due 23:59 2022-03-27
In the IEEE 754 single precision format, what is the bitstring of the fractional part (mantissa) of the decimal number 0.1 in the default rounding mode, rounding to nearest, ties to even?
In the field of reals, the identity element \(a\) of addition satisfies the following three conditions.
Write an R program that computes \[
\sum_{i=1}^{\infty}i
.
\] Will the computations overflow? If so, approximately at what value of i
? Or will the series converge? If so, to what value, and approximately at what value of i
? Explain the observed behavior of R in terms of the parameters of the IEEE 754 standard.
Answer the same questions as above, but for \[ \sum_{i=1}^{\infty}\frac{1}{i} . \]
Consider the evaluation of \(e^x\) using the Taylor series \[
e^x = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \dotsb
\] in R. Write function expTaylor()
that takes a double-precision floating point number x
and executes the following.
stop <- 100
ex <- 1
xi <- 1
ifac <- 1
for (i in 1:stop) {
xi <- xi * x
ifac <- ifac * i
ex <- ex + xi / ifac
}
ex
Now let x <- 20.0
. A correct implementation of expTaylor()
should yield 485165195.40979015827
(with options(digits=20)
, which is close enough to 485165195.40979027748
that the built-in fuction exp()
yields.
Compare the values of expTaylor(-20.0)
and 1 / expTaylor(20.0)
. Calculate the relative error of the two values, assuming that exp(-20.0)
is the true value. Explain what you found.
We can think of the algorithm given in the R code above as an iterative algorithm in i
. At each value of i
, there is a difference in the value of ex and the true value ex
. (The exact value of this difference is the truncation error.) Modify the code (or use different code) to determine the relative error in ex
for each value of i
. For x = 20.0
, make a plot of the relative error and the number of iterations (that is, of i
) for 1 to 100 iterations. Now, repeat this for x = −20.0
. Explain what you found.
Determine the order of the error for approximating ex
with the Taylor series for x = 20
in terms of the number of iterations (that is, the number of terms in the Taylor series).
Rcpp::cppFunction('int float32bin(double x) {
float flx = (float) x;
unsigned int binx = *((unsigned int*)&flx);
return binx;
}')
to inspect single-precision floating point numbers. Figure out and explain what the included C++ code does.
Show the following facts about triangular matrices. A unit triangular matrix is a triangular matrix with all diagonal entries being 1.
The product of two upper (lower) triangular matrices is upper (lower) triangular.
The inverse of an upper (lower) triangular matrix is upper (lower) triangular.
The product of two unit upper (lower) triangular matrices is unit upper (lower) triangular.
The inverse of a unit upper (lower) triangular matrix is unit upper (lower) triangular.
An orthogonal upper (lower) triangular matrix is diagonal.