Capter 8 Finite Difference Metod 81 2nd order linear pde in two variables General 2nd order linear pde in two variables is given in te following form: L[u] = Au xx +2Bu xy +Cu yy +Du x +Eu y +Fu = G According to te relations between coefficients, te pdes are classified into 3 categories, namely, elliptic if AC B 2 > 0 ie, A, C as te same sign yperbolic if AC B 2 < 0 parabolic if AC B = 0 Furtermore, if te coefficients A,B and C are constant, it can be written as [ [ x, y ] A B B C Auxiliary condition BC Interface Cond IC ][ u x u y ] +Du x +Eu y +Fu = G wesay well posed ifasolutionexists Terearebasically twoclassofmetod to discretize it, 1
2 CHAPTER 8 FINITE DIFFERENCE METHOD (1) Finite Difference metod (2) Finite Element metod 82 Finite difference operator Let u(x) be a function defined on Ω R n Let U i,j be te function defined over discrete domain {(x i,y j )} suc tat U i,j = u(x i,y j ) Suc functions are called grid functions We introduce difference operators on te grid functions δ + U i = U i+1 U i, forward difference i+1 δ U i = U i U i 1, backward difference i δ 0 U i = U i+1 U i 1 i + i+1, central difference δ 2 U i = 2(δ+ δ ) i + i+1, central 2nd difference Example 821 Consider te following second order differential equation : u (x) = f(x),u(a) = c,u(b) = d Given a mes a = x 0 < x 1 < < x N = b, x i = x i+1 x i =, we ave U i 1 2U i +U i+1 2 = f i = f(x i ), i = 1, N 1,U 0 = c,u N = d wicdeterminesu i uniquely Weobtainan(N 1) (N 1) matrixequations 2 1 1 2 1 1 2 1 1 2 U 1 U N 1 = 2 f 1 f N 1 c 0 + 0 0 Above equation can be written as L U = F, called a difference equation for a given differential equation d
82 FINITE DIFFERENCE OPERATOR 3 Exercise 822 Write down a matrix equation for te same problem wit second boundary condition canged to te normal derivative condition at b, ie, u (b) = d If one uses first order difference for derivative, we lose accuracy We need an extra equation in tis case Tere are several coices: (1) Use first order backward difference sceme U 1 U n 1 = d and append tis to te last eq( first order) (2) Use central difference equation by assuming a fictitious point U N+1 and assume te DE olds at te end point: Use 1 2(U N 1 2U N +U N+1 ) = f(1) (81) Solve te last eq and substitute into first eq 1 2 (U N+1 U N 1 ) = b (82) 1 2 (U N U N 1 ) = b + 1 f(1) (83) 2 Eq 83 can beviewed as centered difference approximation to u (x n 2 ) and rs as te first two terms of Taylor expansion u (x n 2 ) = u (x n ) 2 u (x n )+ (3) Use so tat u u N u N 1 u N u N 1 = d u N u N 1 = d+f(1) = f(1) Tis is interpreted as using Taylor series of u (1 ) = u (1)+f(1) = u (1) u (1)Butlsiscentereddifferencetou(1 2 ) Sonotconsistent (4) Approximate u (1) by iger order sceme suc as u N 2 4u N 1 +3u N = b
4 CHAPTER 8 FINITE DIFFERENCE METHOD Example 823 (Heat equation) We consider u t = σu xx, for 0 < x < 1, 0 < t < T u(t,0) = u(t,1) = 0 u(0,x) = g(x), g(0) = g(1) = 0 Let x i = i,i = 0,,N, x = 1/N and t n = n t, t = T J Ten we ave te following difference sceme U n+1 i t U n i [ U n = σ i 1 2Ui n +Ui+1 n ] x 2, for i = 1,2,,N 1 and n = 1,2,,M 1 were U n i u(t i,x n ) From te boundary condition and initial condition we ave In vector notation U n+1 i U 0 i = g(x i ),U n 0 = 0,Un N = 0 = Ui n + σ t [ U n x 2 i 1 2Ui n +Ui+1 n ] U n+1 = U n σ t x 2AUn were A is te same matrix as in example 1 If n = 0, rigt and side is known Tus U n = (I σ t x 2A)n G, G = (g(x 1 ),,g(x N 1 )) T Tis is called forward Euler or explicit sceme If we cange te rigt and side to U n+1 i t U n i U n+1 i = σ [ ] U n+1 i 1 2Un+1 i +Ui+1 n+1 x 2 = Ui n + σ t [ U n+1 x 2 i 1 2Un+1 i +Ui+1 n+1 ] (I +σ t x 2A)n U n = G, G = (g(x 1),,g(x N 1 )) T Tis is called backward Euler or implicit sceme
82 FINITE DIFFERENCE OPERATOR 5 821 Error of difference operator For u C 2, use te Taylor expansion about x i u i+1 u i i u i+1 = u(x i + i ) = u(x i )+ i u (x i )+ 2 i 2 u (ξ), ξ (x i,x i+1 ) u (x i ) = i 2 u (ξ) Expand about x i+1, u i = u i+1 i u (x i )+ i 2 u (θ) Tese are first order accurate To derive a second order sceme, expand about x i+1/2, u i+1 = u i+1/2 + i 2 u (x i+1/2 )+ 1 2 ( i 2 )2 u (x i+1/2 )+ 1 6 ( i 2 )3 u (3) (ξ) Subtracting, u i = u i+1/2 i 2 u (x i+1/2 )+ 1 2 ( i 2 )2 u (x i+1/2 ) 1 6 ( i 2 )3 u (3) (ξ) u i+1 u i i = u (x i+1/2 )+O( 2 i) Tus we obtain a second order approximation to u (x i+1/2 ) By translation, we ave u i+1 u i 1 2 i u (x i ) = O( 2 i /6) if i = i+1 Assume i = i+1 and we substitute te solution of differential equation into te difference equation Using u = f we obtain ( u i 1 +2u i u i+1 ) 2 f(x i ) = 1 2( u i +u i 2 2 u i + 3 6 u(3) 4 24 u(4) (θ 1 )+2u i ) + 1 2( u i u i 2 2 u i 3 6 u(3) 4 24 u(4) (θ 2 )) f(x i ) = u i f(x i) 2 24 (u(4) (θ 1 )+u (4) (θ 2 )) truncation error = 2 12 max u(4) We let τ = L u F and call it te truncation error(discretization
6 CHAPTER 8 FINITE DIFFERENCE METHOD error) Definition 824 We say a difference sceme is consistent if te truncation error approaces zero as approaces zero, in oter words, if L u f 0 in some norm Truncation error measures ow well te difference equation approximates te differential equation But it does not measure te actual error in te solution Use of different quadrature for f Instead of f(x i ) we can use 1 12 [f(x i 1)+10f(x i )+f(x i+1 )] = 5 6 f(x i)+ µ 0 6 f(x i) were µ 0 f(x i ) is te average of f wic is f(x i )+O( 2 ) HW Let u = f Sow te following for uniform grid u i 1 +2u i u i 1 2 = 1 12 [f(x i 1)+10f(x i )+f(x i+1 )]+C 4 max u (6) (x) Definition 825 L is said to be stable if U C L U C F for all > 0 were U is te solution of te difference equation, L U = F Also note tat L is stable if and only if L 1 is bounded Definition 826 A finite difference sceme is said to converge if U u 0 as 0 U u is called a discretization error Teorem 827 (P Lax) Given a consistent sceme, stability is equivalent to convergence Proof Assume stability From L u f = τ,l U F = 0, we ave L (u U ) = τ Tus, u U C L (u U ) = C τ 0 Hence te sceme converges Obviously a convergent sceme must be stable
83 ELLIPTIC EQUATION 7 From te teory of pde, we know u C f Hence U U u + u O(τ )+C f C f C F 83 Elliptic equation 831 Basic finite difference metod for elliptic equation In tis capter, we only consider finite difference metod First consider te following elliptic problem:(diriclet problem by Finite Difference Metod) u = f in Ω u = g on Ω (1) Approx DE (u xx +u yy ) = f at eac interior mes pt (2) Te unknown function is to be approximated by a grid function u (3) Replace te derivative by difference quotient u(x+) = u(x)+u x (x)+ 2 2 u xx(x)+ 3 6 u xxx(x)+o( 4 ) u(x ) = u(x+) 2u(x)+u(x ) 2 = u xx (x)+o( 2 ) u xx (x,y) = [u(x+,y) 2u(x,y)+u(x,y)]/ 2 u yy (x,y) = [u(x,y +) 2u(x,y)+u(x,y )]/ 2 Tis picture is called, Molecule, Stencil, Star, etc For eac point (interior mes pt), approx 2 u = u by 5-point stencil By Girsgorin disc teorem, te matrix is nonsingular L[u] is called differential operator wile L [u] is called finite difference operator, eg, L [u] = 1 2[ 4u(x,y)+u(x+,y)+u(x,y)+u(x,y +)+u(x,y )]
8 CHAPTER 8 FINITE DIFFERENCE METHOD (x,y +) (x,y) (x,y) (x+,y) (x,y ) Figure 81: 5-point Stencil or more generally, [ ] L[u] = [ x, u y ]Diag{a x 11,a 22 } +cu = (a u 11 u x ) x (a 22 u y ) y +cu y Uniform meses u x = u(x+) u(x ) 2 u x(x+ (u x ) x = 2 ) ux(x 2 ) Central difference u x (x+ 2 ) = u(x+) u(x) u x (x 2 ) = u(x) u(x ) (a 11 u x ) x = [(a 11 u x )(x+ 2 ) (a 11u x )(x 2 )]/ Assume te differential operator is of te form(wit c > 0) wose discretized form L[u] (u xx +u yy )+cu = f L [U] = a 0 U(x,y) a 1 U(x+,y)+ = F(x,y) 1 2 4+c 2 1 1 0 1 4+c 0 1 1 0 4+c 2 1 0 1 1 4+rc 2 U 1 U 2 U 3 U 4 = f
83 ELLIPTIC EQUATION 9 satisfies (1) L [u] = L[u]+O( 2 ) as 0 u is true solution (2) AU = F +BC, Au = [ u cu+o( 2 )]+BC A(U u) = O( 2 ) = ε Ten te discretization error U u = A as te form 1 ε(depends on ) and satisfies U u A 1 ε A 1 O( 2 ) More generally wen te unit square is divided by n = 1/ equal intervals along x-axis and y-axis, ten te corresponding matrix A(wit c = 0) is (n 1) (n 1) block-diagonal matrix of te form: B I 0 I B I 0 A = 1 2 I (84) B I 0 I B were 4 1 0 1 4 1 0 B = 1 4 1 0 1 4 is (n 1) (n 1) matrix If we put D = diaga = {a 11,,a nn }, ten D 1 A(U u) = D 1 ε Write D 1 A = I +B, were B is off diagonal Ten we know B = 4 4+c 2 < 1 if c > 0 Tus (D 1 A) 1 = (I +B) 1 exists and Hence (D 1 A) 1 = (I +B) 1 1 1 B 4+c2 c 2 U u (D 1 A) 1 D 1 ε 4+c2 2 c 2 4+c 2O(2 ) = O( 2 ) 0
10 CHAPTER 8 FINITE DIFFERENCE METHOD Tus, we ave proved te following result Teorem 831 Let (1) u C 4 (Ω) (2) r > 0 (3) uniform mes Ten U u = O( 2 ) as 0 84 Parabolic pde s Consider a eat equation on a bar u t = u xx, 0 x 1, 0 < t T T g(t) Ω (t) f(x) 1 Figure 82: Domain Teorem 841 (Maximum principle) If u satisfies te above condition for t T, ten min{f,g,} = m Proof Put v = u+ex 2, E > 0 min u max u M = max{f,g,} 0 x 1,0 t T 0 x 1,0 t T v t 2 v x 2 = 2E < 0
84 PARABOLIC PDE S 11 If v attains a maximum at Q intω, ten v t (Q) = 0, v xx (Q) 0 Tus (v t v xx )(Q) 0, a contradiction Hence v as maximum at a boundary point of Ω u(x,t) v(x,t) maxv(x,t) M +E Since E was arbitrary, te proof is complete For minimum, use E instead of E More general parabolic pde u t = Au xx +Du x +Fu+G Explicit write down te values of grid function FDM Implicit variables implicitly representing te value Let te grid be given by 0 = x 0 < x 1 < x 2 < < x N+1 = 1, x i = i, uniform grid 0 = t 0 < t 1 <, t j = jk u = g 1 (y) u = g 2 (y) 2 3 4 u = f(x) Figure 83:
12 CHAPTER 8 FINITE DIFFERENCE METHOD Explicit metod = u t U i,j+1 U i,j k U i+1,j 2U i,j +U i 1,j 2 = uxx U i,j+1 = λu i 1,j +(1 2λ)U i,j +λu i+1,j were λ = k/ 2 Stability: Error doesn t accumulate In tis case solution remains bounded as time goes on Teorem 842 If u is sufficiently smoot, ten u xx u(x+,t) 2u(x,t)+u(x,t) = O(2 ) as 0 2 and u t u(x,t+k) u(x,t) k = O(k) as k 0 Teorem 843 Suppose u is sufficiently smoot, and satisfies u t = u xx 0 < x < 1, t > 0 u(x,0) = f(x) u(0, t) = g(t) u(1,t) = (t) If U i,j is te solution of te explicit finite difference sceme, ten for 0 < λ 1 2, max u i,j U i,j = O( 2 +k) as,k 0, i,j ie, finite difference solution converges to te true solution Proof Put u ij u(x i,t j ) Ten from (1) u i,j+1 u i,j k = u t +O(k) (2) u i+1,j 2u i,j +u i,j 2 = u xx +O( 2 ) we get u i,j+1 = u i,j + k 2(u i+1,j 2u i,j +u i 1,j )+k(o(k)+o( 2 ))
84 PARABOLIC PDE S 13 Hence u i,j+1 = λu i 1,j +(1 2λ)u i,j +λu i+1,j +Ck(k+ 2 ) Let te discretization error be w i,j = u ij U ij so tat w i,j+1 = λw i 1,j +(1 2λ)w i,j +λw i+1,j +O(k 2 +k 2 ) Since 0 < λ 1 2, 0 1 2λ < 1, tree coefficient are positive and teir sum is 1 (convex combination) We see w i,j+1 λ w i 1,j +(1 2λ) w i,j +λ w i+1,j +M(k 2 +k 2 ) for some M > 0 If we define w j = max 1 i N w i,j, ten w j+1 w j +M(k 2 +k 2 ) Since w 0 = 0, w j 1 +2M(k 2 +k 2 ) w 0 +(j +1)M(k 2 +k 2 ) w j+1 (j +1)kM(k + 2 ) TM(k+ 2 ), (j +1)k T In fact, M = max (1 0 x 1,0 t T 2 u tt + k2 12 u xxxx ) Remark 844 If λ > 1 2, te solution may not converge 0 ǫ 0 Figure 84: Nonzero point
14 CHAPTER 8 FINITE DIFFERENCE METHOD Exercise 845 Prove te formula is unstable for λ > 1 2 Let ε, x = 1 2 u(x,0) = wit g = = 0 0, x 1 2 Hence U i,j+1 = λu i+1,j +(1 2λ)U i,j +λu i 1,j, λ = k/ 2 U i,j+1 = λ U i+1,j +(2λ 1) U i,j +λ U i 1,j, 1 i N 1 N 1 i=1 N 2 U i,j+1 = λ i=1 since U(x i,t) = 0, i = 1,N Let S(t j ) = N i=1 U(i,j) Ten N 1 U i+1,j +(2λ 1) i=1 U i,j +λ N U i 1,j, S(t j+1 ) = (4λ 1)S(t j ) = (4λ 1) 2 S(t j 1 ) = = (4λ 1) j+1 S(0) = (4λ 1) j+1 ε Since te number of nonzero U i,j for eac j is 2j + 1(Ceck te numerical sceme, you will see solution is alternating along x-direction dispersing bot direction) tere is a point (x p,t j ) suc tat i=2 U(x p,t j ) 1 2j +1 S(t j) = 1 2j +1 (4λ 1)j ε wic diverges as j since 4λ 1 > 1 Considering te alternating sign, one can see te solution alternates: For j = 1, we see U i,1 = (1 2λ)ǫ,U i 1,1 = λǫ,u i+1,1 = λǫ U i,2 = 2λ 2 ǫ+(1 2λ) 2 ǫ,u i 1,2 = (1 2λ)ǫ+(1 2λ)ǫ = 3λǫ(1 2λ) < 0 Stability of linear system U 1,j+1 U N 1,j+1 = 1 2λ λ 0 λ 1 2λ 0 λ λ 1 2λ U 1,j U N 1,j + g(t j ) 0 0 (t j )
84 PARABOLIC PDE S 15 In vector form, U j+1 = AU j +G j Assume G j = 0, j = 1,2, Let µ be an eigenvalue of A Ten by G-disk teorem, 1 2λ µ 2λ 2λ 1 2λ µ 2λ 2λ 1+2λ+µ 2λ 1 4λ µ 1 If 0 < λ 1 2, ten 1 µ 1, ence stable If λ > 1 2, ten µ > 1 is possible So te sceme may be unstable Te following example sow it is actually unstable Example 846 (Issacson, Keller) Try v(x,t) = Re(e iαx wt ) = cosαx e wt v t v xx v(x,t+ t) v(x,t) = v(x+ x,t) 2v(x,t)+v(x x,t) ( t x 2 e w t ) 1 = v(x,t) cos(αx+α x) 2cosαx+cos(αx α x) t x 2 ( e w t 1 = v(x,t) 2cosα x 2 ) t x 2 e wt = v(x,t) 1 t {e w t [(1 2λ)+2λcosα x]} = v(x,t) 1 [ ( e w t 1 4λsin 2 α x )] t 2 Tusv is asolution of tedifference equation provided w andαsatify e w t = 1 4λsin 2 α x 2 Wit IC v(x,0) = cosαx, solution becomes ( v(x,t) = cosαxe wt = cosαx 1 4λsin 2 α x ) t t 2 Clearly, for all λ 1 2, v(x,t) 1 However, if λ > 1 2, ten for some x, we ave 1 4λsin 2 α x 2 > 1 So v(x,t) becomes arbitrarily large for sufficiently large t/ t Since every even function as a cosine series, we may give any even function f(x) of te form f(x) = n α ncos(απx) to get an unstable problem
16 CHAPTER 8 FINITE DIFFERENCE METHOD Implicit Finite Difference Metod Given a eat equation u t = u xx u(0,t) = g(t), t > 0 u(1,t) = (t) u(x,0) = f(x), 0 x 1 We discretize it by implicit difference metod U i,j+1 U i,j t = U i+1,j+1 2U i,j+1 +U i 1,j+1 x 2 i = 1,,N 1 Multiply by t, ten wit λ = t/ x 2, we ave U i,j+1 U i,j = λu i+1,j+1 2λU i,j+1 +λu i 1,j+1 U i,j = λu i+1,j+1 (1+2λ)U i,j+1 +λu i 1,j+1 j = 1,,N 1 Tis yields a system of N 1 unknowns in {U i,j+1 } N 1 i=1 λu 0,j+1 0 + 0 λu N,j+1 U 1,j U N 1,j (1+2λ) λ 0 λ (1+2λ) λ = 0 λ U 1,j+1 U N 1,j+1 0 λ (1+2λ) Teorem 847 Te implicit finite difference sceme is stable for all λ = t/ x 2 (solution remains bounded) Proof For eac j, let U k(j),j be cosen so tat U k(j),j U i,j, i = 1,,N 1 We coose i 0 = k(j +1) in te following relation U i,j+1 = U i,j +λ{u i+1,j+1 2U i,j+1 +U i 1,j+1 }
84 PARABOLIC PDE S 17 Ten (1+2λ)U i0,j+1 = U i0,j +λ{u i0 +1,j+1 +U i0 1,j+1} for 1 i N 1 Taking absolute values, (1+2λ) U i0,j+1 U i0,j +λ( U i0 +1,j+1 + U i0 1,j+1 ) U i0,j +2λ U i0,j+1 Tus U i0,j+1 U i0,j U k(j),j and ence U i,j+1 U i0,j+1 U k(j),j for 1 i N 1, and U i,j+1 M = max{f,g,}, for i = 0 or N, by boundary condition Repeat te same procedure until we it te boundary U i,j+1 U k(j),j U k(0),0 M = max(f,g,) Using te matrix formulation: We ceck te eigenvalues of te system AU j+1 = U j +G j Eigenvalue of A satisfies µ +(1 +2λ) 2λ by G-disk teorem From tis, we see µ 1 and ence te eigenvalues of A 1 is less tan one in absolute value Tus U j+1 A 1 (U j +G j ) = = A j 1 U 0 +A j 1 G 0 +A j 2 G 1 + +A 1 G j U j+1 A j 1 U 0 + A 1 1 1 A 1 max G j remain bounded Note A does not ave 1 as eigenvalues and all te eigenvalues are positive real Teorem 848 For sufficiently smoot u, we ave u ij U ij = O( 2 +k) as and k 0 (for all λ) Proof Let u ij = u(x i,t j ) be te true solution Ten we ave u i,j+1 u i,j k = 1 2{u i+1,j+1 2u i,j+1 +u i 1,j+1 }+O( 2 +k)
18 CHAPTER 8 FINITE DIFFERENCE METHOD Let w i,j = u i,j U i,j be te discretization error Ten w i,j+1 = w i,j +λ{w i+1,j+1 2w i,j+1 +w i 1,j+1 }+O(k 2 +k 2 ) (1+2λ)w i,j+1 = w i,j +λw i+1,j+1 +λw i 1,j+1 +O(k 2 +k 2 ) Let w j = max i w i,j Ten (1+2λ) w i,j+1 w j +2λ w j+1 +O(k 2 +k 2 ) and so (1+2λ) w j+1 w j +2λ w j+1 +O(k 2 +k 2 ) Tus w j+1 w j +C(k 2 +k 2 ) w 0 +C(j +1)k(k + 2 ) w 0 +CT(k+ 2 ) = CT(k+ 2 ) for t = (j +1)k T