Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

HW2 for CS 6210

You may (and probably should) talk about problems with the each other, with the TA, and with me, providing attribution for any good ideas you might get. Your final write-up should be your own.

md"""
# HW2 for CS 6210

You may (and probably should) talk about problems with the each other, with the TA, and with me, providing attribution for any good ideas you might get. Your final write-up should be your own.
"""
3.0 ms
using LinearAlgebra
296 μs
using Plots
3.6 s

1. Connect the dots

Give a numerical example of a dot product that is computed to low relative accuracy in Julia using the standard algorithm.

md"""
# 1. Connect the dots

Give a numerical example of a dot product that is computed to low relative accuracy in Julia using the standard algorithm.
"""
262 μs

2. Rewriting puzzle

The following block of code considers three methods for computing $z = (e^x-1)/x$:

md"""
## 2. Rewriting puzzle

The following block of code considers three methods for computing $z = (e^x-1)/x$:
"""
275 μs
let
# Range of test values for x
xs = 10.0.^-(1:15)

# Reference computation (high relative accuracy)
z1s = expm1.(xs)./xs

# Naive computation
z2s = (exp.(xs).-1.0)./xs

# Alternate formulation
ys = exp.(xs)
z3s = (ys.-1.0)./log.(ys)

# Relative errors for the two formulations vs reference
abs.(z2s.-z1s)./abs.(z1s), abs.(z3s.-z1s)./abs.(z1s)
end
162 μs

The alternate formulation agrees much better with the reference computation than the naive computation does. Can you explain why? Give a first-order Taylor expansion of $z$ as a function of $x$ near $x = 0$; how well does this agree with the reference computation, and why?

md"""
The alternate formulation agrees much better with the reference computation than the naive computation does. Can you explain why? Give a first-order Taylor expansion of $z$ as a function of $x$ near $x = 0$; how well does this agree with the reference computation, and why?
"""
286 μs

3. Low rank revisited

Argue that, absent overflow or underflow, the floating point code

u = x*dot(y,z)

actually yields $\hat{u} = \hat{x} \hat{y}^T z$ where $\hat{y}_i = y_i (1+\delta_i)$ with $|\delta_i| \lesssim n \epsilon_{\mathrm{mach}}$ and $\hat{x}_i = y_i (1 + \eta_i)$ with $\eta_i \leq \epsilon_{\mathrm{mach}}$

md"""
## 3. Low rank revisited

Argue that, absent overflow or underflow, the floating point code

u = x*dot(y,z)

actually yields $\hat{u} = \hat{x} \hat{y}^T z$ where $\hat{y}_i = y_i (1+\delta_i)$ with $|\delta_i| \lesssim n \epsilon_{\mathrm{mach}}$ and $\hat{x}_i = y_i (1 + \eta_i)$ with $\eta_i \leq \epsilon_{\mathrm{mach}}$
"""
767 μs