03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

278 CHAPTER 14. NUMERICAL EXERCISES<br />

We use the property that<br />

det(A − λI) = det(R)<br />

Since R is upper triangular, the determinant is the product of the diagonal elements of R.<br />

The matrices A are constructed as follows. Start with a simple case : the diagonal matrix with<br />

elements 1, 2, . . . , n on the main diagonal. Then do the tests <strong>for</strong> the same matrix multiplied<br />

on left and right by a random orthogonal matrix X, as in A = XDX T where D is a diagonal<br />

matrix.<br />

g the minimum of a convex function<br />

This exercise is a programming exercise on Newton’s method. First, we explain the method <strong>for</strong><br />

a function with a single variable, then we discuss the case of multivariate functions, and finally,<br />

we show a small application.<br />

14.6.1 Functions in one variable<br />

For a differentiable function f, the minimum ˜x is attained <strong>for</strong> f ′ (˜x) = 0. So, we must find the<br />

zero of the first order derivative. When f is a second order polynomial, we have<br />

then an extreme value of f is attained <strong>for</strong><br />

which is a minimum when f ′′ ≡ 2γ > 0.<br />

f = p := α + βx + γx 2<br />

f ′ = p ′ := β + 2γx<br />

˜x = − β<br />

2γ<br />

(14.6)<br />

For an arbitrary function, we do not have such simple explicit <strong>for</strong>mulae. We can use an iterative<br />

method, which is called Newton’s method. It is an iterative approach, i.e. we start from an<br />

initial guess ˜x and improve this value until it has converged to the minimum of the function. On<br />

each iteration we approximate the function by a degree two polynomial, <strong>for</strong> which the simple<br />

<strong>for</strong>mula (14.6) can be used. One way to compute such a degree two polynomial is to start from<br />

the Taylor expansion of f around ˜x :<br />

f(x) = f(˜x) + f ′ (˜x)(x − ˜x) + 1<br />

2 f ′′ (˜x)(x − ˜x) 2 + · · · .<br />

If we approximate f by the first 3 terms (i.e. a degree two polynomial), then we have<br />

f(x) ≈ p(x) := f(˜x) + f ′ (˜x)(x − ˜x) + 1<br />

2 f ′′ (˜x)(x − ˜x) 2 .<br />

If x is close to ˜x, |f(x) − p(x)| is small. The first order derivative is<br />

f ′ (x) ≈ p ′ (x) = f ′ (˜x) + f ′′ (˜x)(x − ˜x) .

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!