The vectorsl a u contain the subdiagonal diagonal and

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: diagonal entries of an n-by-n % tridiagonal matrix A. The solution of the system % Ax = b is returned in x. The lower and upper % triangular factors are stored as l and u. % n = length(a) Factorization for i = 2:n l(i) = l(i)/a(i-1) a(i) = a(i) - l(i)*u(i-1) end % Forward substitution x(1) = b(1) for i = 2:n x(i) = b(i) - l(i)*x(i-1) end % Backward substitution x(n) = x(n)/a(n) for i = n-1: -1: 1 x(i) = (x(i) - u(i+1)*x(i))/a(i) end 6 Pivoting with Banded Systems Pivoting alters the bandwidth { The upper bandwidth is enlarged { Example 2. Interchange the rst two rows of the matrix of Example 1 2 3 a21 a22 a23 6 a11 a12 7 6 7 6 a31 a32 a33 a34 7 6 A = 6 a42 a43 a44 a45 7 7 6 7 6 7 4 5 a53 a54 a55 a56 a64 a65 a66 The upper bandwidth is now q = 2 { Some data structures cannot handle bandwidth changes Others (to be discussed) can 7 Finite Di erence Computation Example 3. A two-point boundary value problem ;w00 + w = 0 0<x<1 w(0) = 0 w(1) = 1 { The exact solution is w(x) = sinh x sinh 1 Finite Di erence Approximation: { Introduce a mesh of spacing h = 1=(n + 1) on 0 1] Let xi = ih, i = 0 : n + 1 11 11 11 00 00 00 11 11 11 11 11 11 00 00 00 00 00 00 11 00 11 00 w wi w n+1 w(x) w 1 x0 x1 x i-1 xi x xn+1 i+1 x { Approximate w00(xi) by central di w00(xi) erences wi;1 ; 2wi + wi+1 h2 wi is the nite di erence approximation of w(xi) { Approximate the ODE at xi wi;1 ; 2wi + wi+1 + w = 0 ; i h2 8 Finite Di erence Computation Multiply by h2 ;wi;1 + (2 + h2)wi ; wi+1 { The discretization error is O(h2) =0 Use the di erence equation at all interior mesh points { Use the boundary conditions w0 = 0, wn+1 = 1 (2 + h2)w1 ; w2 = 0 i=1 ;wi;1 + (2 + h2)wi ; wi+1 = 0 i=2:n;1 ;wn ; 1 + (2 + h2)wn = 1 i=n The result is a tridiagonal linear system Ax = b with 3 2 2 ;1 2+h 6 ;1 2 + h2 ;1 7 6 7 7 6 ... A=6 7 6 7 ;1 2 + h2 ;1 5 4 ;1 2 + h2 x = w1 w2 wn]T 9 b= 00 1]T Finite Di erence Computation The input to tridi is 2 3 2 2+h 6 2 + h2 7 a = 6 .. 7 6 7 4 5 2 + h2 23 ;1 6 ;1 7 l = u = 6 .. 7 67 45 ;1 Condition number of A as a function of n n 3 7 15 31 63 127 h 1/4 1/8 1/16 1/32 1/64 1/128 A) 2( 5.3629 23.0147 93.6675 367.2897 1506.8 6028.7 { 2(A) = O(1=h2) A)h2 2( 0.3352 0.3596 0.3659 0.3675 0.3679 0.3680 Accuracy and condition are at odds 10 23 0 607 b = 6 .. 7 67 45 1 Two-Dimensional Finite Di erences Example 4. Solving Poisson's equation on a square ; w := ;wxx ; wyy = f (x y ) (x y) 2 w = g(x y) (x y) 2 @ { = f(x y)j0 < x y < 1g { Divide into N 2 squares of size h h with h = 1=N { Let xi = ih, yj = jh y, j N (i,j) j 1 j=0 i=0 1 N i 11 x, i 2D Finite Di erences Approximate derivatives by central di erences wxx(xi yj ) wi;1 j ; 2w2ij + wi+1 j h w wy y(xi yj ) wi j;1 ; 2h2ij + wi j+1 { wij is the nite di erence approximation of w(xi yj ) { Approximate the PDE at (xi yj ) wi;1 j ; 2wij + wi+1 j ; wi j;1 ; 2wij + wi j+1 ; h2 h2 = f (xi yj ) or ;(wi;1 j + wi+1 j + wi j ;1 + wi j +1) + 4wij = h2f (xi yj ) The di erence equation at (xi yj ) connects wij to unknowns at its north, east, south, and west neighbors The discretization error is O(h2) 12 2D Finite Di erences Use the di erence equation at all interior nodes { Use the boundary conditions near edges and corners For a 3 3 grid: write the di erence equation at the points (1 1), (2 1), (1 2), and (2 2) (0,3) (1,3) (2,3) (3,3) (0,2) (1,2) (2,2) (3,2) (0,1) (1,1) (2,1) (3,1) (0,0) (1,0) (2,0) (3,0) 4w11 ; w21 ; w12 = h2f11 +...
View Full Document

Ask a homework question - tutors are online