11.07.2015 Views

Iterative methods to solve a linear system

Iterative methods to solve a linear system

Iterative methods to solve a linear system

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Institute of Scientific ComputingTechnical University BraunschweigProf. Hermann G. MatthiesDr. Alexander LitvinenkoWinter Term 2012/201313.11.2012Introduction <strong>to</strong> PDEs and Numerical Methods:Assignment 4: <strong>Iterative</strong> Linear SolversExercise 1: <strong>Iterative</strong> Linear SolversDownload the matlab library for iterative <strong>solve</strong>rs from the semesterapparat (Prof. H. G. Matthies)http://www.biblio.tu-bs.de/semapp/Start programs elltrit1.m for 1D example and elltrit2.m for 2D exampleStart different iterative <strong>methods</strong> <strong>to</strong> observe convergence.Look inside these programs and find how the convergence is evaluated.Exercise 2: <strong>Iterative</strong> Linear SolversConsider the stationary heat equation(40 points)−β ∂2 u(x)∂x 2 = fon the domain [0, 100] with β = 2.0 and boundary conditions u(0) = 0 and u(100) = 1. Discretisingthe equation by using finite differences leads <strong>to</strong>Au = f.In this exercise no explicit source/sink terms should be introduced. Remark: the analytical solutionis u(x) = 1100 x.(a)The SOR method can be derived by choosing M := (D + ωL) in the matrix splitting methodMu n+1 = Mu n + ω(f − Au n ),where A = D + L + U with diagonal matrix D, strictly lower triangular matrix L and strictly uppertriangular matrix U of A.Write a MATLAB function realising the SOR method. The signature of the function shall be[u, err, iter] = my sor( A, f, u0, <strong>to</strong>l, max iter )with matrix A, right hand side f, start vec<strong>to</strong>r u0. Use the discrete norm of the residual ||Au − f|| asthe error of the method with||a|| = √ 1 nn∑a 2 i , a ∈ Rn .i=1S<strong>to</strong>pping criterion: When the error is smaller than <strong>to</strong>l or the number of iterations larger thanmax iter, the method shall s<strong>to</strong>p and return the actual solution u, the achieved error err and the


equired number of iterations iter.(15 points)(b) Write a MATLAB code which uses your SOR implementation <strong>to</strong> <strong>solve</strong> the <strong>linear</strong> <strong>system</strong>, specifiedat the beginning of this exercise.(10 points)(c)Extend your MATLAB code of (b), so that you can plot the convergence of SOR with respect<strong>to</strong> the given <strong>system</strong>. For it, plot the relative error||u − u it ||||u||over the number of iterations, where u is the analytical solution given by the mentioned functionand u it the approximated one got from the iterative method. For each number of discrete points –50, 100, 200 – plot the relative error over the given number of iterations – 100, 200, . . . , 1000 – andchoose for ω the values 1.0, 1.5 and 1.9. Put all nine graphs in<strong>to</strong> one figure. To make the figureunderstandable use different line-types, plot symbols and colors, Use also the MATLAB commandlegend <strong>to</strong> name the graphs.(15 points)

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

Saved successfully!

Ooh no, something went wrong!