1. Homework #1ΒΆ

For all programming assignments, please turn in your code along with your solution. Submissions should be made on Sakai.

Problem 1

What are the approximate absolute and relative errors in approximating \(\pi\) by each of the following quantities?

  1. \(3\)
  2. \(3.14\)
  3. \(22/7\)

You can use either single or double precision for your computations. Please state your choice.

Problem 2

In either single or double precision, is the machine epsilon the smallest number \(\varepsilon\) that can be stored on the computer, such that \(1+\varepsilon\neq 1\)? Justify your answer.

Problem 3

Write a program to compute the absolute and relative errors in Stirling’s approximation

\[n! \approx \sqrt{2\pi n}(n/e)^n\]

for \(n=1,2,\ldots,10\). Does the absolute error grow or shrink as \(n\) increases? Does the relative error grow or shrink as \(n\) increases? Is the result affected when using double precision instead of single precision?

Problem 4

Let \(x\in\mathbb R^n\) be an \(n\)-dimensional vector. Show that \(\lVert x\rVert_2\) and \(\lVert x\rVert_\infty\) are equivalent.

Problem 5

Consider the image blurring example discussed in class, and suppose we denote the matrix of grayscale pixel values as \(I\). Modify the Python script blur.py to use the following operation instead:

\[\begin{split}I[i,j] \enspace &=& \enspace \frac{1}{16}(8\cdot I[i,j] + I[i-1,j] + I[i-1,j-1] + I[i-1,j+1] + I[i,j-1] \\ \enspace &+& \enspace I[i,j+1] + I[i+1,j] + I[i+1,j-1] + I[i+1,j+1])\end{split}\]

Compute the blurred image after \(20\) iterations of this modified scheme.