An archived instance of discourse for discussion in undergraduate Real and Numerical Analysis.

# Exam 2 Review

gbrock

I guess we can just post our answers to various questions in here.

I'll start off with the first problem: Compute the LU decomposition of the matrix $\begin{pmatrix} 1& 3\\ 5& 10 \end{pmatrix}$.

Right off the bat, we'll need to pivot because, believe it or not, $5>1$. Anyway, we can then subtract $\frac{1}{5}$ times the first row from the second row. Between the pivot, the subtraction and the $\frac{1}{5}$ thing, we should (hopefully) get:

$U = \begin{pmatrix} 5& 10\\ 0& 1 \end{pmatrix}$
$L = \begin{pmatrix} 1& 0\\ \frac{1}{5}& 1 \end{pmatrix}$.
$P = \begin{pmatrix} 0& 1\\ 1& 0 \end{pmatrix}$.

ctyra

why do we have to pivot again
I got
\begin{pmatrix} 1& 0\\ 0& 1 \end{pmatrix} \begin{pmatrix} 1& 0\\ 5& 1 \end{pmatrix} \begin{pmatrix} 1& 3\\ 0& -5 \end{pmatrix}

gbrock

I don't think you have to pivot. My understanding from class is that pivoting is a good habit to get into because it causes less error on a computer when dealing with small numbers.

mark

@ctyra You gotta pivot because the algorithm is much more numerically stable that way. You won't notice this when you do an exact computation with a simple integer matrix like this, but you can really tell the difference with a matrix like
$$\left( \begin{matrix} 10.0^{-10} & 1.0 \\ 1.0 & 0.0 \end{matrix} \right).$$
To be clear - you must pivot. It's part of the algorithm.

Invictus

For #2 as we discussed in class:

We create the A matrix by filling the columns with the coefficients of our equation. Since our equation was $f(x) = ax + b$ it would be 1's and our x values.

$A = \begin{pmatrix} 1&1 \\ 1&2 \\ 1&4 \end{pmatrix}$

We use this to fill in the equation:

$A^TAc = A^Ty$

Which gives us:

$$\begin{pmatrix} 1&1&1 \\ 1&2&4 \end{pmatrix} * \begin{pmatrix} 1&1 \\ 1&2 \\ 1&4 \end{pmatrix} * \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} 1&1&1 \\ 1&2&4 \end{pmatrix} * \begin{pmatrix} 2 \\ 3 \\ 4 \end{pmatrix}$$

which simplifies to:

$$\begin{pmatrix} 3&7 \\ 7&21 \end{pmatrix} * \begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} 9\\21 \end{pmatrix}$$

Which gives us the equations:

$3a + 7b = 9$
$7a + 21b = 24$

Shia

For problem 3 on Exam Review 2, we are given the integral $$\int_{-1}^1 \cos(x^2) dx$$

Which we are to approximate using a trapezoidal sum within $10^{-6}$ of the actual value.

From our notes in previous classes, I have that a trapezoidal approximation to an integral would be $$\int_a^b f(x)dx \approx T_n = \sum_{i=1}^n \frac{f(x_i)+f(x_{i-1})}{2}\Delta x.$$

To approximate the error, I have that the difference between the actual integral value and our trapezoidal sum is:

$$|I-T_n|\leq \frac{D}{12}\frac{(b-a)^3}{n^2},$$
where $D$ is a bound on $f''$ over our the bounds of the integral. From examining the graph in the Exam Review 2, we can see that there is an upper bound around 2 for $f''(x)$, but we'll set our bound to 3 just to be safe.

This leaves us with the following:
$$|I-T_n|\leq \frac{3}{12}\frac{(1- -1)^3}{n^2}=\frac{1}{4}\frac{8}{n^2}=\frac{2}{n^2}$$

So to keep our error less than $10^{-6}$, we would want $n$ such that
$$\frac{2}{n^2}=10^{-6},$$
which we can solve for $n^2=2*10^6$, or $n=\sqrt{2}*1000$. From here, we can loosely overestimate 1.5 for $\sqrt{2}$ and know that with 1500 terms, we'll be well within our acceptable error tolerance.

For part b, we would simply want to find a way to linearly map each term $i$ to a separate, evenly spread point along out range of -1 to 1; from what Mark covered in class today, it seemed fairly effective to simply add $\frac{i}{n}$ to the lower bound as shown below:

$$\int_{-1}^1 \cos(x^2)dx \approx T_n = \sum_{i=1}^{1500} \frac{1}{2}\left(\cos((\frac{i-1}{1500}-1)^2)+\cos((\frac{i}{1500}-1)^2)\right)\Delta x.$$