{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw8s - CME302 Homework 8 Computer Exercise A.M.B 10 0(T&B...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CME302 Homework 8 Computer Exercise A.M.B. November 16, 2009 (T&B 38.6) The code for this problem follows: function [x rc ra] = cg(A,b,nits) n = length(b); x = zeros(n,1); r = b; p = r; rc = zeros(1,nits+1); ra = rc; rc(1) = norm(b); ra = rc(1); for(i = 1:nits) Ap = A*p; r1 = dot(r,r); alpha = r1/dot(p,Ap); x = x + alpha*p; r = r - alpha*Ap; r2 = dot(r,r); rc(i+1) = sqrt(r2); ra(i+1) = norm(b - A*x); beta = r2/r1; p = r + beta*p; end function [x r] = steep(A,b,nits) n = length(b); x = zeros(n,1); p = -b; r = zeros(1,nits+1); r(1) = norm(b); for(i = 1:nits) alpha = dot(p,p)/dot(p,A*p); x = x + alpha*p; p = b - A*x; r(i+1) = norm(p); end Figure 1 shows the convergence results for the problem Ax = b . The subplot zooms in on the first several iterations. Comments: In CG, bardbl e n bardbl A = bardbl r n bardbl A - 1 decreases monotonically, but bardbl r n bardbl 2 does not. This is evident in our problem. The green and blue curves increase during approx- imately iterations 12 to 18, while the cyan curve is monotonically decreasing. (You were not asked to plot bardbl r n bardbl A - 1 , but I wanted to. In practice only bardbl r n bardbl 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

hw8s - CME302 Homework 8 Computer Exercise A.M.B 10 0(T&B...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online