Lecture+21--Tridiagona.+_+LU+decomposition

Lecture+21--Tridiagona.+_+LU+decomposition - Hand...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Hand Calculations: Tridiagonal Matrix (a) Forward elimination 1-2-3 1-1-1 1-0.5 1 1 4 - = ------ 5 3 2 5 3 x x x x 25 1 5 5 2 1 1 5 2 2 1 4 3 2 1 . . . . 2 2 2 1 1 2 2 2 1 1 2 5 ( 2) 1 1 2 5 ( 3) 1 1 e f f g f e r r r f- =- =-- = - =- =-- = - 3 3 3 2 2 2 3 2 1 1 1 2 ( 1) 1 1 1 2 ( 1) 1 1 e f f g f e r r r f- =- =-- = - =- =-- = 4 4 4 3 3 4 4 4 3 3 0.5 1.25 ( 0.5) 1 1 0.5 3.5 (1) 4 1 e f f g f e r r r f- =- =-- = - =- =- = Hand Calculations: Tridiagonal Matrix (b) Back substitution 1 2 3 4 1 2 3 1 1 1 1 0.5 1 1 4 x x x x-- -- = - 4 4 4 4 4 1 r x f = = = 1 1 2 1 1 3 ( 2)(2) 1 1 r g x x f-- - - = = = 3 3 4 3 3 1 ( 0.5)(4) 3 1 r g x x f-- - = = = 2 2 3 2 2 1 ( 1)(3) 2 1 r g x x f-- - - = = = MATLAB M-file: Tridiag function x = Tridiag(e,f,g,r) % Tridiag: Tridiagonal equation solver banded system % x = Tridiag(e,f,g,r): Tridiagonal system solver. % input: % e = subdiagonal vector % f = diagonal vector % g = superdiagonal vector % r = right hand side vector % output: % x = solution vector n=length(f); % forward elimination for k = 2:n factor = e(k)/f(k-1); f(k) = f(k) - factor*g(k-1); r(k) = r(k) - factor*r(k-1); end % back substitution x(n) = r(n)/f(n); for k = n-1:-1:1 x(k) = (r(k)-g(k)*x(k+1))/f(k); end One loop; Operation count: ~8n NOT 2 n3/3 No modification on g [e,f,g,r] = example...
View Full Document

This note was uploaded on 11/07/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Page1 / 14

Lecture+21--Tridiagona.+_+LU+decomposition - Hand...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online