1 Finite-Difference Method For The 1D Heat Equation: 1.1 Domain Discretization
1 Finite-Difference Method For The 1D Heat Equation: 1.1 Domain Discretization
1 Finite-Difference Method For The 1D Heat Equation: 1.1 Domain Discretization
Math679/Fall 2012
(1)
We will employ the nite-dierence technique to obtain the numerical solution to (1). In this technique, the approximations require that the model domain (space) and time be discretized. The space domain is represented by a network of grid cells or elements and the time of the simulation is represented by time steps. The accuracy of the numerical method will depend upon the accuracy of the model input data, the size of the space and time discretization, and the scheme used to solve the model equations.
1.1
Domain Discretization
L M
We rst partition the intervals [0, L] and [0, T ] into respective nite grids as follows. We let, xi = ix, Similarly we partition [0, T ] as, tn = nt, n = 0, 1, 2, . . . , N where t = T N i = 0, 1, . . . , M where x =
1.2
We consider the Forward in Time Central in Space Scheme (FTCS) where we replace the time derivative in (1) by the forward dierencing scheme and the space derivative in (1) by the central dierencing scheme. This yields, ui+1,n 2ui,n + ui1,n ui,n+1 ui,n 2 0 t (x)2 where ui,n u(xi , tn ). This can be simplied to yield, ui,n+1 = (1 2)ui,n + (ui+1,n + ui1,n ) where the parameter = 2 t (x)2 (2)
We would impose (2) only on the interior nodes, namely for i = 1, 2, . . . , M 1 and for n = 1, 2, . . . , N . Since the initial condition is given in (1), numerically we have, ui,0 = (xi ), i = 0, 1, 2, . . . , M 1
Padmanabhan Seshaiyer
Math679/Fall 2012
The explicit nature of the dierence method can then be reexpressed in matrix form as,
a b
where a = 1 2, b = and n = 0, 1, . . . , N . It must be pointed out that eventhough the implementation of the FTCS method looks simple and attractive, one has to take caution when making appropriate choices of x and t. This is illustrated in the following example. Consider the initial data: x (x) = cos (3) x Then it is clear that this data oscillates exactly with spatial frequency of the grid because, (xi ) = (ix) = (1)i One can show that the exact solution to the heat equation (1) for this initial data satises, |u(x, t)| for all x and t. So, it is reasonable to expect the numerical solution to behave similarly. Unfortunately, this is not true if one employs the FTCS scheme (2). For this scheme, with the initial data given in (3), it is possible to prove that the numerical solution satises, ui,n = (1)i (1 4)n (4)
Therefore, inorder for the computed discrete approximation to be bounded as n , we require that, |1 4| < 1 which yields the restriction, (x)2 t 2 This for a choice of x = 0.1, the FTCS scheme (for = 1, say) will become unstable if the initial data oscillates on the order of x, unless, we choose t to be, t 0.005 This is a very small step size and so to make the FTCS scheme stable is not always practical.
Padmanabhan Seshaiyer
Math679/Fall 2012
1.3
Let us suppose that the solution to the dierence equations is of the form, (5)
where j = 1. Now we examine the behaviour of this solution as t or n for a suitable choice of . Note that if |ent | > 1, then this solutoin becomes unbounded. Hence we want to study solutions with, |ent | 1 Consider the dierence equation (2). Substituting (5) in (2) and rearranging terms yields, et = 1 4 sin2 x 2
Obviously et 1. Hence we look for solutions that satisfy, ent 1 Since sin2
x 2
1.4
Instead of the FTCS, one could have alternatively considered the following Backward in Time Central in Space (BTCS) dierencing scheme for (1): ui,n+1 ui,n ui+1,n+1 2ui,n+1 + ui1,n+1 2 0 t (x)2 where ui,n u(xi , tn ). This can be simplied to yield, ui,n = (1 + 2)ui,n+1 (ui+1,n+1 + ui1,n+1 ) (7)
for i = 1, 2, . . . , M 1 and for n = 1, 2, . . . , N . Note that unlike the FTCS method, we are required to solve a system each time. The implicit nature of the dierence method can then be reexpressed in matrix form as,
a b
0 0 0 . . .
where a = 1 + 2, b = and n = 0, 1, . . . , N . 3
Padmanabhan Seshaiyer
Math679/Fall 2012
1.5
Note that letting the solution to be of the form (5), then (7) simplies to, et =
This implies that any numerical solution obtained via the BTCS scheme is stable. Hence for any value of , the BTCS is unconditionally stable.
1.6
The FTCS and BTCS schemes indicate that one can generate a whole range of schemes based on the following discretization: ui,n+1 ui,n = [(1 )(ui+1,n 2ui,n + ui1,n ) + (ui+1,n+1 2ui,n+1 + ui1,n+1 )] (8)
Note that for = 0 and = 1, (8) yields the Explicit FTCS and Implicit BTCS respectively. A more popular scheme for implementation is when = 0.5 which yields the Crank-Nicolson scheme which is also unconditionally stable.
Padmanabhan Seshaiyer
Math679/Fall 2012
Homework
1. Analyze the numerical stability of the weighted average or theta-method. In particular, show that (a) If 0 < 0.5, then the method is stable if and only if 0.5. (b) If 0.5 1, then the method is unconditionally stable, i.e., stable for all (or all t and x.) 2. Consider the problem, ut u(0, t) u(1, t) u(x, 0) = = = = uxx 0 < x < 1, 0 < t < 0 0<t< 0 0<t< sin(x) 0 x 1
(a) Determine the analytical solution to the problem. (b) Write a MATLAB Program to implement the problem via Explicit Forward in Time Central in Space (FTCS) nite dierence algorithm. Let x and t be the stepsizes in space and time respectively (i.e. the grid points are dened according to xj = j x, j = 0, 1, , M and tn = nt, n = 0, 1, . . . , N ) with nal time T = N t = 0.5. Run your program and compare the nite dierence solution uj,n with the exact solution u(xj , tn ) from part(a) for x = 0.1, t = 0.01 and x = 0.1, t = 0.0005. If E n := max{|uj,n u(xj , tn )|, j = 0, 1, , M }. Plot the log(E n ) with respect to tn for n = 0, 1, , N . (c) Repeat part(b) for an Implicit Backward in Time Central in Space (BTCS) nite dierence algorithm. (d) Repeat part(b) for an Implicit Crank-Nicholson nite dierence algorithm. 3. Consider the one-dimensional viscous Burgers equation for a given velocity u and viscocity coecient . ut + u ux = uxx u(x, 0) = (x) (a) Consider the transformation u(x, t) = 2 vx (x, t) v (x, t) (10) x R, t > 0 xR (9)
for a function v (x, t). Using the transformation (10), show that if v (x, t) satises the heat equation (vt = vxx ) then u(x, t) is a solution to the PDE in (9). (b) Also, use the transformation (10) to prove that for some constant C , v (x, 0) = Ce 2
1 x 0
(s) ds