Docsity

Numerical Computing - Homework 4 - Fall 2009 | CSCI 4800, Assignments of Computer Science

Toggle sidebar
bg1
Numerical Computing S’09 MATH/CSCI 4800-01
Homework-4
Due in class on Thursday March 5, 2009
Illegible reports will be returned without grading. Show all work. All Matlab scripts, Matlab output and
plots should be printed out and stapled to the report.
1. (Pencil-and-paper and computer) In class we considered three iterative methods for solving linear
systems of type Ax =b; the Jacobi method, the GS (Gauss-Seidel) method and the SOR (successive
over-relaxation) method. See sections 2.5.1 and 2.5.2 of the Text. In component form the Jacobi
iteration is written as
x(k+1)
i=bi−Pi−1
j=1 aijx(k)
j−Pn
j=i+1 aijx(k)
j
aii
,(1)
while the corresponding formula for the GS iteration is
x(k+1)
i=bi−Pi−1
j=1 aijx(k+1)
j−Pn
j=i+1 aijx(k)
j
aii
.(2)
In many practical problems the matrix Ais sparse, i.e., many of its entries are zeros. In such cases
the iterative methods can be particularly attractive, from the points of view of both storage (zero
entries need not be stored) and operation count. One frequently occurring example of a sparse matrix
is the tridiagonal matrix, which has nonzero entries only along the main diagonal and the diagonals
immediately above (superdiagonal) and below (subdiagonal) the main diagonal. For example, such a
matrix of order 5 can be written as
A=
d1u1000
`2d2u20 0
0`3d3u30
0 0 `4d4u4
0 0 0 `5d5
.(3)
Only the entries di, `iand uineed be stored. The notation can be extended in an obvious way to a
square matrix of arbitrary order n.
Sparse matrices are discussed in section 2.5.4 of the Text but here we take a slightly different approach.
(a) Rewrite the formulas (1) and (2) for a tridiagonal matrix Aof order n, using the notation
introduced in (3). (You may need to treat x(k+1)
1and x(k+1)
ndifferently.)
(b) Let Abe a tridiagonal matrix with 4 as each entry on the main diagonal and -1 on the diagonals
above and below the main. Let bbe a vector of all ones. Write a well-commented Matlab script
to solve Ax =bto a relative error of 10−6using the Jacobi iteration and the formulas derived
in part (a). You may use the relative error to be
||x(k+1)−x(k)||
||xk+1|| +10−16
(The term 10−16 is added to the denominator to guard against the case ||x(k+1)|| =0.) You
may use the infinity norm, for which the Matlab notation is norm(x,inf). Print out the iteration
number and the solution for each iteration. Comment on your results.
(c) Repeat part (b) above using the GS method. Comment on your results and compare with those
of part (a).
(d) (Extra credit) Repeat part (b) above using the SOR method. Choose the relaxation parameter ω
to lie in the interval (1,1.5).Experiment with several values of ωand comment on the results,
comparing them with those of parts (b) and (c) above.
pf2

Partial preview of the text

Download Numerical Computing - Homework 4 - Fall 2009 | CSCI 4800 and more Assignments Computer Science in PDF only on Docsity!

Numerical Computing S’09 MATH/CSCI 4800- Homework-

Due in class on Thursday March 5, 2009

Illegible reports will be returned without grading. Show all work. All Matlab scripts, Matlab output and plots should be printed out and stapled to the report.

  1. (Pencil-and-paper and computer) In class we considered three iterative methods for solving linear systems of type Ax = b; the Jacobi method, the GS (Gauss-Seidel) method and the SOR (successive over-relaxation) method. See sections 2.5.1 and 2.5.2 of the Text. In component form the Jacobi iteration is written as

x (k+1) i =^

bi −

∑i− 1 j=1 aij^ x

(k) j −^

∑n j=i+1 aij^ x

(k) j aii

while the corresponding formula for the GS iteration is

x( ik +1)=

bi −

∑i− 1 j=1 aij^ x

(k+1) j −^

∑n j=i+1 aij^ x

(k) j aii

In many practical problems the matrix A is sparse, i.e., many of its entries are zeros. In such cases the iterative methods can be particularly attractive, from the points of view of both storage (zero entries need not be stored) and operation count. One frequently occurring example of a sparse matrix is the tridiagonal matrix, which has nonzero entries only along the main diagonal and the diagonals immediately above (superdiagonal) and below (subdiagonal) the main diagonal. For example, such a matrix of order 5 can be written as

A =

d 1 u 1 0 0 0 2 d 2 u 2 0 0 0 3 d 3 u 3 0 0 0 4 d 4 u 4 0 0 0 5 d 5

Only the entries di, `i and ui need be stored. The notation can be extended in an obvious way to a square matrix of arbitrary order n. Sparse matrices are discussed in section 2.5.4 of the Text but here we take a slightly different approach.

(a) Rewrite the formulas (1) and (2) for a tridiagonal matrix A of order n, using the notation introduced in (3). (You may need to treat x (k+1) 1 and^ x

(k+1) n differently.) (b) Let A be a tridiagonal matrix with 4 as each entry on the main diagonal and -1 on the diagonals above and below the main. Let b be a vector of all ones. Write a well-commented Matlab script to solve Ax = b to a relative error of 10−^6 using the Jacobi iteration and the formulas derived in part (a). You may use the relative error to be

||x(k+^1 )^ − x(k)|| ||xk+^1 || + 10 −^16

(The term 10 −^16 is added to the denominator to guard against the case ||x(k+^1 )|| = 0. ) You may use the infinity norm, for which the Matlab notation is norm(x,inf). Print out the iteration number and the solution for each iteration. Comment on your results. (c) Repeat part (b) above using the GS method. Comment on your results and compare with those of part (a). (d) (Extra credit) Repeat part (b) above using the SOR method. Choose the relaxation parameter ω to lie in the interval (1, 1 .5). Experiment with several values of ω and comment on the results, comparing them with those of parts (b) and (c) above.

  1. (Pencil-and-paper and computer) Consider the three equations

x^21 + 2 sin x 2 + x 3 = 0 , cos x 2 − x 3 = 2 , x^21 + x^22 + x^23 = 2.

We seek the solution for x 1 , x 2 and x 3 using Newton’s method for nonlinear systems. As we discussed in class, (also see section 2.7.1 of the Text), Newton’s method applies to nonlinear systems of form fi(x 1 , x 2 , · · · xn) = 0, i = 1, 2 , · · · n. Given the n th iterate (^) 

   

x (n) 1 x (n) 2 · · · x (n) n

the method computes the increment (^) 

   

∆x( 1 n) ∆x( 2 n) · · · ∆x( nn)

by solving a related linear system J(n)∆x(n)^ = −f (n), where J is the Jacobian matrix. The n + 1 th iterate is then given by x(n+1)^ = x(n)^ + ∆x(n).

(a) Compute by hand the Jacobian matrix of the given 3 × 3 system. (b) Implement Newton’s method numerically to solve the given system. Your code must print at each iteration the following information: the iteration number, the solution at that iteration, and the norm of the increment to the solution at that iteration. Terminate the solution when the infinity norm of the increment to the solution is smaller than 10 −^6. Use the initial guess x 1 = 1. 1 , x 2 = 0. 1 , x 3 = − 0. 9. You may use as a guide the Matlab routines that are available on line under the title Newton2d scripts, or you may write your own script. If the online scripts are used, note that they are provided in a single file for ease of access. You must put each script in an m-file of its own. Further, the scripts must be modified to suit the problem and the display requirements stated above. (c) Repeat part (b) with the initial guess x 1 = 1, x 2 = 1, x 3 = 0. Comment on the result.

  1. (Pencil-and-paper) In class we discussed determination of the polynomial interpolant to a set of discrete data points by three methods: monomial basis, Lagrange basis and Newton basis. Use each of these methods to find the polynomial interpolant for the data set (− 1 , 10), (0, −4), (1, −2), (2, 2). Show that the answer is the same in each case.
  2. (Pencil-and-paper) Text, page 159, section 3.2 Exercises, problem 2.
  3. (Pencil-and-paper) Text, page 169, section 3.3 Exercises, problems 2(c), 4.