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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

276 CHAPTER 14. NUMERICAL EXERCISES<br />

14.4.2 Dictionary application<br />

The page ranking algorithm which was described above can also be used to rank different words<br />

in a dictionary. Consider the following small dictionary:<br />

backwoods = bush, jungle<br />

bush = backwoods, jungle, shrub, plant, hedge<br />

flower = plant<br />

hedge = bush<br />

jungle = bush, backwoods<br />

plant = bush, shrub, flower, weed<br />

shrub = bush, plant, tree<br />

tree = shrub<br />

weed = plant<br />

Construct a graph linking every word with the words in its explanation. The first line of the<br />

dictionary, <strong>for</strong> example, would link bush and jungle to backwoods. The graph can be constructed<br />

on paper. Use equation (14.4) to construct the sparse column stochastic matrix A and use your<br />

power method to rank the words.<br />

o of a function in an interval<br />

In this exercise, we make a programming exercise on a root finding method, called the bisection<br />

method.<br />

14.5.1 Functions in one variable<br />

Suppose we are given a function f in one variable and we want to compute the unique zero<br />

in the interval [a, b]. A method that could be used is the bisection method. It only requires<br />

function evaluations and is thus widely applicable.<br />

The method computes a small interval that contains the minimum. This small interval is<br />

obtained by splitting the interval [a, b] in two parts [a, m] and [m, b], where<br />

The method works as follows :<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

m =<br />

a + b<br />

2<br />

1. Given the interval [a, b] <strong>for</strong> which f(a)f(b) < 0.<br />

2. Repeat until b − a < τ:<br />

2.1. Compute m from (14.5).<br />

2.2. If f(m)f(a) < 0: b = m.<br />

2.2. Else: a = m.<br />

(14.5)

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

Saved successfully!

Ooh no, something went wrong!