Numerical Methods MATH 417 - 501/502 A. Bonito April 7 Spring 2016 Last Name: First Name: Homework 8 Exercise 1 35% (MATLAB) Implement the following conjugate-gradient algorithm in matlab: • Inputs: A ∈ Rn×n , b, x0 ∈ Rn . • Initialization Compute: r0 = b − Ax0 , and α1 = w1 = −r0 , (r0 )T w1 , (w1 )T z1 z1 = Aw1 x1 = x0 + α 1 w 1 . • Main loop For i = 1, 2, 3, ..., compute: ri = ri−1 − αi zi , (if kri k2 < tol stop), βi = (ri )T zi , (wi )T zi and αi+1 = wi+1 = −ri + β i wi , (ri )T wi+1 , (wi+1 )T zi+1 zi+1 = Awi+1 xi+1 = xi + αi+1 wi+1 • Outputs: xi and kri k Consider now the following linear systems Ax = b, where A = (aij )ni,j=1 , 2 −1 aij = 0 i=j |i − j| = 1 otherwise and b = (bi )ni=1 , bi = 1, x0 = (x0i )ni=1 , x0i = 0. Together with your matlab code, report the number of iterations for the conjugate gradient algorithm to reach a tolerance of 10−8 as well as the tolerance reached for n = 5, 10, 20, 40, 80, 160. Exercise 2 35% (MATLAB) You will learn in this exercise how to employ a least-square method to denoise data. Consider the function g(x) = 1.7 sin(2πx) + 0.47 sin(4πx) + 0.73 sin(6πx) + 0.8 sin(8πx) 3i for i = 0, ..., 50. The measured for x ∈ (0, 3) at 51 equi-distributed points, this is xi = 50 measurements are polluted with random noise. This means that you are actually given (in matlab) the vector F: g = inline('1.7*sin(2*pi*x)+ 0.47*sin (4*pi*x) + 0.73*sin(6*pi*x) + 0.8*sin(8*pi*x)'); F = g(linspace(0,3,51)).' + .4*randn(51,1); Write a least-square method to to find the coefficients αj , j = 1, ..., 8 in gLS (x) = 8 X αj sin(jπx), j=1 so that 50 X (Fi − gLS (xi ))2 i=1 is minimized. You can use matlab backslash routine to solve the linear solver. Hand out your matlab code as well as two plots: one of (xi , Fi ) together with (x, gLS (x)) and the other one of (x, g(x)) together with (x, gLS (x)). Exercise 3 30% (BY HAND) We want to solve the linear system Ax = b where 2 −1 A= and −1 2 b= 1 1 . 1. Check that A is symmetric and positive definite. 2. Perform two iterations of the conjugate gradient method starting with 3 0 2 x = 2 and verify that x2 = x is the solution of the linear system. 3. Let 1 T y Ay − bT y. 2 Plot the isovalues of L (i.e. the set of y’s such that L(y) = c for several constants c) together with the vectors x0 , x1 and x2 . L(y) :=