Introduction to Finite Differences Lim |Uj − U(Xj, Tn)| = 0 H,4T→0

Introduction to Finite Differences Lim |Uj − U(Xj, Tn)| = 0 H,4T→0

2 Also we frequently need N to represent other quantities and only seldom do we need a notation for the total number of timesteps. n • U denotes the numerical approximation to u. Uj will denote the numerical solution at timestep n and n gridpoint j. If the numerical solution exactly agrees with the true solution, then Uj = u(xj; tn). One goal, though not the only one, of a numerical scheme is to make n Introduction to Finite Differences lim jUj − u(xj; tn)j = 0 h;4t!0 Explicit Euler solution Consider the heat equation on a finite interval subject to Dirichlet boundary conditions and arbitrary (i.e. user specified) initial conditions: @u @2u Basic methodology of finite-difference schemes - approximate the derivatives appearing in the partial dif- PDE: = ; 0 ≤ x ≤ `; t > 0 @t @x2 ferential equation with combinations (differences) of the values on the grid. Here we consider the simplest BC: u(0; t) = γ0 and u(`; t) = γ`; t > 0 case. IC: u(x; 0) = u0(x); 0 ≤ x ≤ `: Approximate time derivative by the forward difference: Assume the γ's are time-independent. n+1 @u @u U − U n j = (x ; t ) ' j j @t j;n @t j n 4t Space-time discretization Approximate space-derivative by the second-order center difference: 2 2 2 n n n @ @ @ u @ u Uj−1 − 2Uj + Uj+1 We need a numerical representation for the function u(x; t) and the for operators @t and @x2 . j = (x ; t ) ' @x2 j;n @x2 j n h2 In the simplest case the dependent variable u is represented by values on a uniform grid or lattice in space and time. The heat equation becomes: n+1 n n n n U − U U − − 2U + U j j = j 1 j j+1 4t h2 n+1 Solving for Uj : n+1 n n n n Uj = Uj + ν(Uj−1 − 2Uj + Uj+1) where ν ≡ 4t=h2. This is an explicit expression for the U's at the n + 1st timestep in terms of the U's at the nth timestep. Taking into account the BCs and IC we have the explicit, or forward, Euler scheme for the heat equation: 0 0 Uj = u (xj); 0 ≤ j ≤ J γ0; j = 0 n+1 n n n n U = U + ν(U − − 2U + U ); 0 < j < J; j 8 j j 1 j j+1 • Divide the interval [0; `] into J equally spaced intervals of size 4x or h. Hence h = 4x = `=J. < γ`; j = J There are a total of J + 1 gridpoints labeled xj. For the uniform grid xj = j4x; j = 0; J : • n labels timesteps, tn denotes discrete time values, and 4t is the timestep. When needed, t0 and tf will denote the initial and final times and N will denote the total number of time steps. Usually t0 = 0 At each new timestep, the dependent variable at each interior grid point is computed from values at three and tn = n4t. gridpoints at the preceding timestep. 1 Numerical methods for PDES Copyright (C) 2002-2005 Dwight Barkley 3 4 More on finite-difference formulas Derivation of finite-difference formulas @ru Difference operators Suppose we want to approximate @xr to some order of accuracy as a weighted sum of values of u on a (possibly non-uniform) grid : : : ; xj−2; xj−1; xj; xj+1; xj+2; : : :: @ru The following difference operators are frequently useful: (x ) ' w u @xr j k j+k Xk • forward difference: where uj+k = u(xj+k). How are the weights wk chosen? ∆+tu(x; t) ≡ u(x; t + 4t) − u(x; t) The trick is to express all the uj+k = u(xj+k) as Taylor series expansions about point xj: ∆+xu(x; t) ≡ u(x + 4x; t) − u(x; t) uj = uj @u @2u (x − x )2 • backward difference: u = u + j (x − x ) + j j+1 j + : : : j+1 j @x j j+1 j @x2 j 2 2 2 ∆−tu(x; t) ≡ u(x; t) − u(x; t − 4t) @u @ u (xj−1 − xj) − − uj 1 = uj + jj(xj 1 − xj) + 2 jj + : : : ∆−xu(x; t) ≡ u(x; t) − u(x − 4x; t) @x @x 2 . • central difference: 1 1 where jj means evaluated at xj. Multiplying each equation by corresponding weight and summing we have: δtu(x; t) ≡ u(x; t + 4t) − u(x; t − 4t) 2 2 r r @u @ u (xj+k − xj) 1 1 wkuj+k = uj wk + jj wk(xj+k − xj) + : : : r jj wk + : : : δxu(x; t) ≡ u(x + 4x; t) − u(x − 4x; t) @x @x r! 2 2 Xk Xk Xk Xk From this follows the second-order central difference: @ru 2 The left-hand-side is the sum that we want to approximate @xr . To achieve this for generic functions u, we δxu(x; t) ≡ u(x − 4x; t) − 2u(x; t) + u(x + 4x; t) @ru @ru must have all terms preceding @xr on the-right-side be zero and the coefficient of @xr be one. In addition @ru we would like as many terms as possible following r also to be zero. This is satisfied by choosing the • @x central difference using double interval: weights such that: 1 1 ∆ u(x; t) ≡ (∆ + ∆− )u(x; t) = (u(x + 4x; t) − u(x − 4x; t)) 0x 2 +x x 2 wk = 0 Xk wk(xj+k − xj) = 0 Xk . (x − x )r w j+k j = 1 k r! Xk (x − x )r+1 w j+k j = 0 k (r + 1)! Xk . These equations are linear in the weights and thus can be solved for the wk in terms of the differences xj+k − xj. The number of gridpoints necessary to approximate a derivative depends on the order r of the derivative and the number of high-order terms in the Taylor series that one want to make zero. Frequently on uniform grids symmetries enter such that with q weights it is possible to satisfy more than q conditions. Numerical methods for PDES Copyright (C) 2002-2005 Dwight Barkley Numerical methods for PDES Copyright (C) 2002-2005 Dwight Barkley 6 Roundoff Error Roundoff errors arise due to finite precision computations. The one rule with regard to roundoff is: Error Analysis Where possible avoid subtracting nearly equal numbers. This rule implies, for example, that one should not take tan(x) for large x. The analysis of errors in numerical schemes is important for the following reasons: Truncation Error • It tells us where errors come from and where we should concentrate efforts to reduce errors. Truncation error T (x; t) is the error in approximating differential operators and PDEs by discrete represen- • It allows comparison of different schemes. tations such as finite differences. • It provides a powerful basis for testing programs. For a PDE written as Fu = 0, T (x; t) = F Au(x; t) where F A is the approximation to the differential equation and u is an exact solution to the PDE. Example: The truncation error for the explicit Euler scheme for the heat equation is u(x; t + 4t) − u(x; t) u(x − h; t) − 2u(x; t) + u(x + h; t) T (x; t) = − 4t h2 @u @2u 4t @2u h2 @4u = (x; t) − (x; t) + (x; t) − (x; t) + : : : @t @x2 2 @t2 12 @x4 4t @2u h2 @4u = (x; t) − (x; t) + : : : 2 @t2 12 @x4 so 2 Th;4t(x; t) = O(4t) + O(h ) @2u @4u We assume j @t2 j and j @x4 j are bounded in the space-time domain of interest. The truncation error goes to zero everywhere in the domain as 4t and h go to zero. Hence the explicit Euler approximation is consistent with the partial differential equation. Discretization Error n The discretization error ej at a point of the computational grid is the difference between the numerical and exact solutions: n n ej ≡ Uj − u(xj; tn) 5 Numerical methods for PDES Copyright (C) 2002-2005 Dwight Barkley 7 8 n 0 where u and Uj satisfy the same initial conditions, i.e. Uj = u(xj; 0). Frequently we are interested in: f E ≡ maxjjejj; for fixed final time tf also called the discretization error (though usage varies). For the explicit Euler solution of the heat equation this can be bounded using the truncation error as long as ν ≤ 1=2. f E ≤ tf T¯: ¯ n ¯ where T is a bound on the truncation error: jTj j ≤ T . Ef ! 0; for 4t; h ! 0 such that ν = 4t=h2 ≤ 1=2 The numerical solution is said to converge to the exact solution. Our main interest is the scaling of discretization error with 4t and h: Ef = jO(4t) + O(h2)j 1 We can investigate the final error Ef (at a fixed final time) as a function of 4t and h. To make this precise, we need a refinement path = (hi; 4ti); i = 0; 1; 2; : : : with hi and 4ti going to zero such that 2 f νi = 4ti=hi ≤ 1=2. We compute the error E at points on the refinement path and verify the scaling of Ef . In practice for testing it is better to vary only one of 4t and h while holding the other constant. The scaling of the discretization error with 4t and h provides a valuable check on the correctness of a program. 1Note: This is slightly subtle in that the discretization error for one-step is 2nd order in 4t, i.e. E1 ≤ 4tjO(4t) + O(h2)j For fixed final time tf the number of timesteps N necessary to reach tf increases as 1=4t decreases (N ∼ 1=4t).

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us