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.

272 CHAPTER 14. NUMERICAL EXERCISES<br />

14.2 The 2D Poisson equation<br />

The 2D Poisson equation is<br />

− ∂2u ∂x2 − ∂2u = f<br />

∂y2 where u(x, y) is the solution and f the excitation and (x, y) ∈ [0, 1] × [0, 1]. We impose the<br />

boundary conditions<br />

u(0, y) = u(1, y) = y(x, 0) = y(x, 1) = 0 .<br />

We discretize the x as xj = jh <strong>for</strong> j = 1, . . . , n and h = 1/n. Similarly, yj = jh. We use finite<br />

differences <strong>for</strong> the second order derivatives. This produces the equation<br />

1<br />

h 2 (−u(xi−1, yj)−u(xi, yj−1)−u (xi+1, yj)−u(xi, yj+1)+4u(xi, yj)) = f(xi, yj) <strong>for</strong> i, j = 1, . . . , n .<br />

This leads to the algebraic system of equations Au = f with n 2 rows and columns.<br />

Recall the example exercise of §14.1. We do exactly the same exercise. Since the matrix is not<br />

tridiagonal, we cannot use the LAPACK routine pttrf any longer. We use the LAPACK routine<br />

sytrf <strong>for</strong> a full matrix instead. See the documentation on<br />

boost-sandbox/libs/numeric/bindings/lapack/doc/index.html.<br />

For a 2D problem the solution vector u can be represented as a matrix. The row index corresponds<br />

to the variable x and the column index to a variable y.<br />

In particular, you develop the functions inverse iteration, poisson 2d <strong>for</strong> the matrix vector product,<br />

scaled poisson <strong>for</strong> the scaled matrix vector product, and richardson. Give <strong>for</strong> each templated<br />

argument the conceptual conditions. make a plot of the eigenvector using Gnuplot’s splot (<strong>for</strong><br />

plotting surfaces).<br />

14.3 The solution of a system of differential equations<br />

In this exercise, we write a function <strong>for</strong> the computation of a time step of a system of differential<br />

equations using Runge-Kutta methods.<br />

14.3.1 Explicit time integration<br />

Methods <strong>for</strong> the solution of the differential equation<br />

˙u = f(u) u(0) = u0<br />

operate time step by time step, i.e. the time is discretized and given the solution at time step<br />

tj, we compute the solution at time step tj+1 = tj + h where h is small.

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

Saved successfully!

Ooh no, something went wrong!