Homework/Programming 6. (Due March 12) Math. 417 This homework involves developing simple matlab functions for implementing Richardson’s iteration for computing the solution of a linear system, (0.1) Ax = b, where A is a nonsingular n × n matrix and x, b ∈ Rn with b given. Richardson’s method is a fixed point iteration with a parameter α ∈ R. Note that (0.1) can be rewritten 0 = b − Ax. Richardson’s method comes from the fixed point formulation, x = x + α(b − Ax) and is given by xj+1 = xj + α(b − Axj ). This method requires an initial iterate x0 . Without a priori information, x0 = 0 ∈ Rn is often used. Write a MATLAB m-file function implementing k steps of Richardson’s iteration with interface: function xn=richardson(x0,k,A,b,al,tol) MATLAB automatically provides basic linear algebra operations however you must understand that MATLAB deals with matrices (not vectors). To declare a column vector, you can write x = ones(n, 1); The “ones” function in MATLAB creates a matrix with every entry set to one (there is also an analogous “zeros” function). As defined above, x is actually a matrix with dimension n × 1 and so (when A is an n × n matrix) y = A ∗ x produces another colum vector y (actually an n × 1 matrix). Note that if you set x = ones(1, n) you would get an 1 × n matrix (a row vector) and the operation y = A ∗ x would result in an error while y = x ∗ A would produce another row vector (dimensioned 1 × n). This means that if xi is a n × 1 matrix and A, an n × n matrix, you can implement the update step in Richardsons iteration as xip = xi + al ∗ (b − A ∗ xi). 1 2 In our examples, we shall measure the error in a weighted norm, specifically, if x ∈ Rn , 1/2 n X −1 2 kxk = n xi i=1 MATLAB provides a function for computing the Euclidean norm of a matrix, namely, if M is an n × m (MATLAB) matrix, the function norm(M ) computes X 1/2 m n X 2 norm(M ) = M (i, j) . i=1 j=1 Thus, if P is the n×1 matrix representing the vector p ∈ Rn , we can compute kpk by norm(P )/sqrt(n);. Thus, we can use norm(xip − xi)/sqrt(n) as our convergence indicator in the MATLAB Richardson’s code. Specifically, we run our iteration until norm(xip − xi)/sqrt(n) < tol The remainder of the assignment involves running your Richardson’s function on various matrices. In all cases, use a right hand side consisting of all ones, i.e., b = ones(n, 1) and an initial iterate x0 = zeros(n, 1). There are three possible outcomes of the iteration: (a) The iterations converge to the unique solution of Ax = b. (b) The iteration diverges (iterates becomes arbitrarily large). (c) The iteration remains bounded but does not converge. In case (a) above, stop the iteration when norm(xip − xi)/sqrt(n) < tol := 10−5 . Problem 1. A is a 3 × 3 diagonal matrix with diagonal entries 1, 2, 4. Run your code for α = {−1, 1, 1/2, 1/4, 2/5} and report whether (a), (b) or (c) holds for each iteration. When (a) holds, report the number of the iteration when the error indicator reaches the tolerence. Problem 2. A is a 3×3 diagonal matrix with diagonal entries 1, 2, −4. Run your code for α = {−2, −1, 1, 2} and report whether (a), (b) or (c) holds for each iteration. When (a) holds, report the number of the iteration when the error indicator reaches the tolerence. 3 Problem 3. For the same A as in the previous problem, we reformulate Ax = b as (3.1) A2 x = Ab (this is called the normal equations). You can use your code to iterate on this equation by passing down A2 as your matrix and Ab as your right hand side vector. Run your code on the normal equations with α = {1, 1/8, 1/16} and report whether (a), (b) or (c) holds for each iteration. When (a) holds, report the number of the iteration when the error indicator reaches the tolerence. Problem 4. For 2 10 A= , 0 4 experiment with different values of α until you have found two which lead to divergence and two which lead to convergence. In the convergent cases, report the iteration number when the error indicator reaches the tolerence. Hand in the results for the four problems and a copy of the matlab code implementing the iteration.