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.

14.5. THE BISECTION METHOD FOR FINDING THE ZERO OF A FUNCTION IN AN INTERVAL277<br />

14.5.2 Software<br />

The task is to first develop the function<br />

template <br />

void bisection( T& a, T& b, Function& f, double tau ) ;<br />

that computes the bisection Algorithm 6. The object f is a functor that returns the function<br />

value <strong>for</strong> a single argument x. The type T is a float type, i.e. float or double.<br />

Write documentation <strong>for</strong> the function and describe the conceptual conditions on Function.<br />

14.5.3 The growth and downfall of a caterpillar population<br />

Everyone knows caterpillars grow up to be beautiful butterflies. But be<strong>for</strong>e they reach that<br />

stage of their life, they need lots of food to grow. A large population will not grow at the same<br />

rate as a smaller one, because of a shortage of food. Furthermore most birds enjoy a juicy<br />

caterpillar as snack, so they are responsible <strong>for</strong> the premature death of several members of the<br />

caterpillar population. These relationships can be modelled mathematically by the following<br />

equation:<br />

dN<br />

dt<br />

N αN 2<br />

= rN(1 − ) −<br />

K β + N 2<br />

In this equation rN(1 − N<br />

) models the growth of the population, where N equals the num-<br />

K<br />

ber of caterpillars, r is the growing rate of the population and K is the maximum amount of<br />

caterpillars that can inhabit the area. The second term of the equation models the death of the<br />

caterpillars. Here α is the maximum rate at which a bird can eat caterpillars when N is large<br />

and β is a parameter that indicates the intensity of the bird attacks. We want to know when<br />

there exists an equilibrium between the growth and death rate in the caterpillar population,<br />

i.e. when dN<br />

equals zero.<br />

dt<br />

Use the function bisection to compute the number of caterpillars N <strong>for</strong> which the following<br />

populations are at an equilibrium in the intervals [0.1; 10], [10, 20] and [20, 100]:<br />

• Population 1: r = 1.3, K = 100, α = 20 and β = 50<br />

• Population 2: r = 2.0, K = 80, α = 25 and β = 10<br />

Show the resulting roots in a table.<br />

14.5.4 Computing eigenvalues using the bisection method<br />

In this exercise, we use the function bisection to compute the eigenvalues of a real symmetric<br />

dense matrix A with real eigenvalues. The problem is to compute λ so that<br />

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

The determinant is computed using the QR factorization (which is available in LAPACK). The<br />

QR factorization computes an orthogonal matrix Q (Q T Q = I) and an upper triangular matrix<br />

R so that<br />

A − λI = QR .

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

Saved successfully!

Ooh no, something went wrong!