UNDERGRADUATE COMPUTATIONAL ENGINEERING AND SCIENCE

UCES

"Boundary Value Problem in 1D"

Course:   Methods and Analysis in UCES

Prerequisites:

  1. Math:   Calculus and algebraic systems
  2. Computing:   Maple and loops
  3. Science:   Physics

Objectives:

  1. Math:   Use of Taylor series, convergence as mesh decreases
  2. Computing:   Software for solving linear systems
  3. Science:   Heat transfer

General Information: This is the first numerical solution of a boundary value problem. The steady state heat conduction via diffusion and via cooling to the surrounding volume is studied. This type of problem is later generalized to two and three space variables as well as more complicated boundary conditions.

Contact Person:   R. E. White, NCSU, white@math.ncsu.edu

Revision Date:   8-3-94

Copyright ©1994, R. E. White. All rights reserved.

Return to Table of Contents


3.1   Boundary Value Problem in 1D

3.1.1.   Introduction.

In the past sections we have considered differential equations whose solutions were dependent on the time variable. The main physical illustration of this was the heat transfer, but we assumed a uniform temperature distribution in the material. This is rarely the case and one can expect to have a varying temperature with respect to space, and this will result in the diffusion of heat. The math model for this is also a differential equation, but at least one of the independent variables must be space. The simplest boundary value problems have the form

-Kuxx + Cu = f and boundary conditions u(0), u(1) given. (1)
u = u(x) could represent temperature and is an unknown function of x, and x is in some finite interval, say [0,1]. K is the thermal conductivity, and for small changes in temperature it can be approximated by a constant. The function f can have many forms:

(i) f = f(x) could be a heat source such as electrical resistance in a wire,

(ii) f = c(usur - u) from Newton's law of cooling,

(iii) f = c(usur4 - u4) from radiative cooling or

(iv) f ~ f(a) + f'(a)(u - a) could be a linear Taylor polynomial approximation of a general source term f(u).

Also, there are other types of boundary conditions which reflect how fast heat passes through the boundary.


3.1.2.   Applied Area.

The derivation of (1) for steady state one space dimension is based on the empirical law known as

Fourier's Heat Law:

(a). heat flows from hot to cold,

(b). the change in heat is proportional to the
cross sectional area,
change in time, and
derivative of temperature.

Figure: Heat Diffusion in a Thin Wire

Consider a thin wire so that there is diffusion in only one direction, x. The f has units of (heat)/(volume time). If there is no time dependence for the temperature, then Fourier's heat law for a thin wire when coupled with Newton's law of cooling to the surrounding region takes the form

zero heat change in heat content is approximately equal to
(heat from electrical resistance)
+ (cooling from surrounding region)
+ (heat from diffusion from the left and right ends).

If r is the radius of the wire and A = pi r2 , then the above is

0 f(x) hA delta t
+ h pi 2r c(usur - u) delta t
+ Kux(x + h)A delta t - Kux(x)A delta t.

K is the constant of proportionality and will depend on the type of material in the wire. If the temperature is larger on the right side of the cylindrical cell depicted in the above figure, then ux(x+h) will be positive and heat will flow into the cell from the right side. A similar argument holds for the left side except the sign will change. This is an approximation because u changes continuously. The approximation will get better as h decreases. Divide both sides of this approximation by hA delta t and let h go to zero to get a variation of (1)

-(Kux )x + 2c/r u = f + 2c/r usur . (2)


3.1.3.   Model.

If K, C and f are constants, then the closed form solution of (1) or (2) is relatively easy to find. However, if they are more complicated or if we have diffusion in two and three dimensional space, then closed form solutions are harder to find. An alternative is the finite difference method which is a way of converting continuum problems such as (1) or (2) into a finite set of algebraic equations. It uses numerical derivative approximation for the second derivative that was discussed at the end of the last section. First, we break the wire into n equal parts with xi = ih and h = (1 - 0)/n. Second, we let ui ~ u(ih) where u(x) is from the continuum solution and ui will come from the finite difference (or discrete) solution. Third, we approximate the second derivative by

uxx(ih) ~ [(ui+1 - ui )/h - (ui - ui-1 )/h]/h.

The finite difference method or discrete model approximation to (1) is for 0 < i < n

-K[(ui+1 - ui )/h - (ui - ui-1 )/h]/h + Cui = fi = f(ih). (3)
This gives n-1 equations for n-1 unknowns. The end point u0 = u(0) and un = u(1) are given as is f(x).

The discrete system (3) may be written in matrix form. For ease of notation we multiply (3) by h2 , let B = 2K + h2 C, and n = 5 so that there are 4 equations and 4 unknowns.


      Bu1 - Ku2                = h2f1 + Ku0

-Ku1 + Bu2 - Ku3 = h2f2

-Ku2 + Bu3 - Ku4 = h2f3

-Ku3 + Bu4 = h2f4 + Ku5

The matrix form of this is the tridiagonal system

AU = F where
  A is, in general, (n-1)×(n-1) matrix and
  U and F are (n-1)×1 column vectors.

Here with n = 5 we have


3.1.4.   Method.

The solution can be obtained by either using the tridiagonal (or Thomas) algorithm, or using a solver that is provided with your computer software. Let us consider the tridiagonal system Ax = d where A is n × n and x and d are n × 1 column vectors. We assume the matrix A has components as indicated in

.

The following important algorithm will be discussed in detail in the following sections.

Tridiagonal Algorithm.

    alpha(1) = a(1)
    gamma(1)= c(1)/alpha(1)
    y(1) = d(1)/alpha(1)
    for i = 2, n
           alpha(i) = a(i)- b(i)*gamma(i-1)
           gamma(i) = c(i)/alpha(i)
           y(i) = (d(i) - b(i)*y(i-1))/alpha(i)
    endloop
    x(n) = y(n)
    for i = n - 1,1
        x(i) = y(i) - gamma(i)*x(i+1)
    endloop.


3.1.5.   Implementation.

Here we use the Maple procedure linsolve to solve the resulting algebraic system. The procedure BVP approximates the solution of the thin wire in (2) where a heat source f = 1 units of heat per volume per time are held constant. We have experimented with different radii of the wire and different c in the cooling to the surrounding region.

Maple Code for Steady State Heat Transfer in a Thin Wire.

  Procedure is Defined:
        > BVP:=proc(n,tcond,r,c,usur,f)
        > with(linalg):
        > with(plots):
        > C:=(2/r)*c:
        > h:= 1/n:
        > Rhs:= h*h*(f + C*usur):
        > A:=matrix(n-1,n-1,0):
        > F:=vector(n-1,0):
        > x:=vector(n-1,0):
        > x[1]:=h:
        > F[1]:= Rhs:
        > A[1,1]:=2*tcond + h*h*C:
        > A[1,2]:=-tcond:
        > for i from 2 to n-2 do
        >     x[i]:=i*h:
        >     F[i]:=Rhs:
        >     A[i,i-1]:= -tcond:
        >     A[i,i]:= 2*tcond + h*h*C:
        >     A[i,i+1]:= -tcond:
        > od:
        > x[n-1]:=(n-1)*h:
        > F[n-1]:=Rhs:
        > A[n-1,n-2]:= -tcond:
        > A[n-1,n-1]:= 2*tcond +h*h*C:
        > solution:=linsolve(A,F):
        > end:

  Input Data:
        > n := 10:
        > tcond := .001:
        > r := .1:
        > c := .01:
        > usur := 0:
        > f := 1:

Call Procedure and Graph Outputs:

The first output uses the above data and the maximum steady state temperature is about 5.

        > BVP(10,.001,.1,.01,0,1);
        > L:=[[0,0],seq([x[i],solution[i]],i=1..9),[1,0]]:

Next we increase the radius from .1 to .2 and the resulting maximum steady state temperature is about 10.

        > BVP(10,.001,.2,.01,0,1);
        > LL:=[[0,0],seq([x[i],solution[i]],i=1..9),[1,0]]:

Now we increase the radius to .3 and the maximum steady state temperature is a little above 14.

        > BVP(10,.001,.3,.01,0,1);
	> LLL:=[[0,0],seq([x[i],solution[i]],i=1..9),[1,0]]:

	> plot({L,LL,LLL},x=0..1);

Figure: Temperature in Thin Wire, r = .1, .2, .3

The last calculation keeps the radius at .3, but decreases the c from .01 to .00001 which decreases the amount of heat lost to the surrounding region. This corresponds to the steady state solution that we previously obtained by using the explicit time discretization.

        > BVP(10,.001,.3,.00001,0,1);
Figure: Temperature in a Thin Wire, c = .00001

The following Matlab code uses the tridiagonal algorithm to appproximate the solution of -uxx + u = 10x(1 - x) with u(0) = 0 = u(1). The number of intervals, n, can be varied, and the numerical and exact solutions can be compared as is illustrated in the table at the end of this section.

Matlab Code for a Simple Boundary Value Problem.

	function x = bvp(n)
	h  = 1/n;
	for i = 1:n-1
	    a(i) = 2 + h*h;
	    b(i) = -1;
            c(i) = -1;
	    d(i) = h*h*f(i*h);
	end
	trid(n-1,a,b,c,d);

	function trid(n,a,b,c,d)
	alpha = zeros(n,1);
	gamma = zeros(n,1);
	y = zeros(n,1);
	alpha(1) = a(1);
	gamma(1) = c(1)/alpha(1);
	y(1) = d(1)/alpha(1);
	for i = 2:n
	    alpha(i) = a(i) - b(i)*gamma(i-1);
	    gamma(i) = c(i)/alpha(i);
	    y(i) = (d(i) - b(i)*y(i-1))/alpha(i);
        end
	x(n) = y(n);
	for i = n-1:-1:1
            x(i) = y(i) - gamma(i)*x(i+1);
	end

3.1.6.   Assessment.

In the above model of heat conduction, the thermal conductivity was held constant relative to the space and temperature. If the temperature varies over a large range, the thermal conductivity will show significant changes. Also, the electrical resistivity will vary with temperature, and hence, the heat source , f, will be a function of temperature.

Another important consideration in this model is the possibility of the temperature being a function of the radial space variable, that is, as the radius increases, the temperature is likely to be vary. Hence, heat will also diffuse in this second space direction.

A third consideration is the choice of mesh size, h. Once the algebraic system has been solved, one wonders how close the numerical solution of the finite difference method (3), the discrete model, is to the solution of the differential equation (1), the continuum model. We want to analyze the discretization error Ei = ui - u(ih). We will neglect any roundoff errors. Use n = 4 in Taylor's theorem and the fact that u(x) satisfies (1) at ih to get

K(u((i-1)h) - 2u(ih) + u((i+1)h))/h2 + f(ih) - Cu(ih) = Ku(4)(ci )/12 h2. (4)

The finite difference method (3) gives

-K(ui-1 - 2ui + ui+1 )/h2 + Cui = f(ih). (5)

Add equations (4) and (5) and use the definition of Ei to obtain

K(-Ei-1 + 2Ei - Ei+1 )/h2 + CEi = +Ku(4) (ci )/12 h2 .

Or,

(2K/h2 + C) Ei = KEi+1 /h2 + KEi-1 /h2 + Ku(4) (ci )/12 h2 .

Let E = max | Ei | where i ranges from 1 to n - 1, and M4 = max | u(4) (x) | where x is in [0,1].

Then for all i

(2K/h2 + C) | Ei | 2KE/h2 + KM4 /12 h2 .

So, it must be true for the i that gives the maximum, and therefore,

(2K/h2 + C) E 2KE/h2 + KM4 /12 h2   and
CE KM4 /12 h2.

We have just proved the next theorem.

Finite Difference Method Error Theorem. Consider the solution of (1) and the associated finite difference system (3). If the solution (1) has four continuous derivatives on [0,1], then for M4 = max | u(4)(x) | where x is in [0,1] and i = 1, ..., n - 1

max | ui - u(ih) | M4/(12C) h2 .

Example. This example will illustrate the second order convergence of the finite difference method which was established in the above theorem. Consider (1) with K = C = 1 and f(x) = 10x(1-x). The exact solution is u(x) = c1 ex + c2 e-x + 10 (x(1. - x) - 2.) and the constants are chosen so that u(0) = 0 and u(1) = 0.

Table: Second Order Convergence
n (h = 1/n) max. error = E E/(h2 )
10 17.0267 10-4 0.1703
20 4.2140 10-4 0.1686
40 1.0865 10-4 0.1738
80 0.2598 10-4 0.1663
160 0.0585 10-4 0.1498


3.1.7.   Homework.

  1. Experiment with the thin wire model. Examine the effects of varying f, C and h.

  2. Write a program for the tridiagonal algorithm and verify the above table.

  3. Consider (1) but with a new boundary condition at x = 1 in the form Kux = (1 - u(1)). Find the new algebraic system associated with the finite difference method.

  4. Find the exact solution of the above, and verify the quadratic convergence of the finite difference method.