Numerical Analysis

Week 1 Lab STMATH 405
1. On the first day of class we attempted to approximate the derivative of sin x in Matlab, using the
formula
d
dx sin x =
sin(x + h) − sin(x)
h
+ O(h) (1)
where the second term represents the discretization error. We saw that when h is sufficiently small,
the overall error in the approximation begins to get worse, due to roundoff (cancellation) error.
(a) The “sum-to-product” trig identity states that
sin α − sin β = 2 cos 
α + β
2

sin 
α − β
2

.
Use this identity to rewrite the numerator in (1) as a product, simplifying the arguments as much
as possible.
(b) Modify the file Example1 3 Figure1 3.m to approximate the derivative your modified formula
from part (a), in addition to the original formula. Plot the error in this approximation on the
same axes as for the original formula.
(c) The two formulas used to approximate the derivative are mathematically equivalent. Why does
the second formula give much better results numerically? (Be specific!)
Please submit: Written responses to parts (a) and (c); code and plot for part (b).
2. The Frobenius norm of a matrix is defined as
kAkF =
sX
i,j
|aij |
2
i.e., we square all elements of the matrix, add them up, then take the square root. This is a useful way
of measuring the “size” of a matrix in some sense. We can also compute the difference between two
matrices A and B using kA − BkF .
(a) Let
A =

1 106
0 1 
A
∗ =

1 106
10−6 1

Compute kAkF and kA − A∗kF , as well as the relative change, kA−A
∗kF
kAkF
.
(b) Use the eig command in Matlab to compute the eigenvalues of A and A∗
. Denote the eigenvalues
of A as λ1, λ2 and those of A∗ as λ

1
, λ∗
2
. Compute the relative change in the eigenvalues as:
∆ =
p
(λ1 − λ

1
)
2 + (λ2 − λ

2
)
2
p
λ
2
1 + λ
2
2
How many times larger is the change in the eigenvalues compared to the change in the matrices
A and A∗
?
(c) Repeat parts (a) and (b) for the following two matrices:
B =

1 10
5 1 
B
∗ =

1 10
5.001 1 
(d) What can you conclude about the conditioning of the two eigenvalue problems? What do you
think this says about the conditioning of eigenvalue problems more generally?
To submit: Written answers to parts (a) – (d). Including Matlab code is optional, but
you should show all the needed computations