21.06.2014 Views

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

0<br />

0<br />

“naive” implementation via “\”:<br />

“structure aware” implementation:<br />

2<br />

2<br />

Obvious fill-in (→ Def. 2.6.3)<br />

4<br />

6<br />

L<br />

8<br />

10<br />

12<br />

0 2 4 6 8 10 12<br />

nz = 65<br />

4<br />

6<br />

U<br />

8<br />

10<br />

12<br />

0 2 4 6 8 10 12<br />

nz = 65<br />

Code 2.6.17: LSE with arrow matrix, implementation<br />

I<br />

1 function x = sa1 ( alpha , b , c , d , y )<br />

2 A = [ alpha , b ’ ; c , diag ( d ) ] ;<br />

3 x = A \ y ;<br />

Code 2.6.19: LSE with arrow matrix, implementation<br />

II<br />

1 function x = sa2 ( alpha , b , c , d , y )<br />

2 z = b . / d ;<br />

3 x i = ( y ( 1 ) −<br />

dot ( z , y ( 2 : end ) ) ) . . .<br />

4 / ( alpha−dot ( z , c ) ) ;<br />

5 x = [ x i ; ( y ( 2 : end )−x i ∗c ) . / d ] ;<br />

Cyclic permutation of rows/columns:<br />

• 1st row/column → n-th row/column<br />

• i-th row/column → i − 1-th row/column,<br />

i = 2,...,n<br />

➣<br />

LU-factorization requires O(n) operations,<br />

see Ex. 2.6.13.<br />

⎛<br />

A =<br />

⎜<br />

⎝<br />

D<br />

b T<br />

⎞<br />

c<br />

⎟<br />

⎠<br />

α<br />

(2.6.2)<br />

Ôº½ ¾º<br />

Ôº½ ¾º<br />

After permuting rows of A from (2.6.2) , cf. (2.2.2):<br />

⎛<br />

⎞ ⎛<br />

L =<br />

I 0<br />

, U =<br />

⎜<br />

⎟ ⎜<br />

⎝<br />

⎠ ⎝<br />

b T D −1 1<br />

➣ No more fill-in, costs merely O(n) !<br />

⎞<br />

D c<br />

, σ := α − b T D −1 c .<br />

⎟<br />

⎠<br />

0 σ<br />

Measuring run times:<br />

t = [];<br />

for i=3:12<br />

n = 2^n; alpha = 2;<br />

b = ones(n,1); c = (1:n)’;<br />

d = -ones(n,1); y = (-1).^(1:(n+1))’;<br />

tic; x1 = sa1(alpha,b,c,d,y); t1 = toc;<br />

tic; x2 = sa2(alpha,b,c,d,y); t2 = toc;<br />

t = [t; n t1 t2];<br />

end<br />

loglog(t(:,1),t(:,2), ...<br />

... ’b-*’,t(:,1),t(:,3),’r-+’);<br />

time[seconds]<br />

10 1<br />

10 0<br />

10 −1<br />

10 −2<br />

10 −3<br />

Implementation I<br />

Implementation II<br />

Solving LSE Ax = y with A from 2.6.1:<br />

two MATLAB codes<br />

Platform as in Ex. 2.6.5<br />

10 2 n<br />

10 −4<br />

10 0 10 1 10 2 10 3 10 4<br />

MATLAB can do much better !<br />

Ôº½ ¾º<br />

Ôº½¼ ¾º

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

Saved successfully!

Ooh no, something went wrong!