UNDERGRADUATE COMPUTATIONAL ENGINEERING AND SCIENCE

UCES

"Stiff Initial Value Problems"

Course:   Methods and Analysis in UCES

Prerequisites:

  1. Math:   Calculus 2
  2. Computing:   Maple and loops
  3. Science:   Heat transfer

Objectives:

  1. Math:   Error estimates
  2. Computing:   Mesh considerations for stiff problems
  3. Science:   Stiff problems

General Information: This section is a continuation of the previous section. Here we focus on stiff problems and a second order accurate discretization scheme.

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


2.5   Stiff Initial Value Problems

2.5.1.   Introduction.

In the previous lecture we fixed the maximum time at T and let the step length, h, vary. Here we will fix the step length and let T be very large or . In the Newton's law of cooling example Euler's method has the form of a first order finite difference algorithm uk+1 = a uk + b with a = 1 - hc and b = hcusur. Hence, if |a| = |1 - hc| > 1, then the computed solutions will eventually blowup. In the calculations presented in the previous section hc = .8097, and so the solution converged very nicely, even if the k is allowed to exceed K. For large enough values of c the computed solution will blowup, but the long run or steady state continuum solution must be usur !

In the Newton's law of cooling model ut = c(usur - u) = f(u), and for large c the derivative of f(u) is a large negative number. In such cases the temperature will rapidly cool to the steady state temperature. Rapid chemical reactions are another illustration of this type of problem. Differential equations in which fu, the derivative of f with respect to u, has large negative values are called stiff differential equations.


2.5.2.   Applied Area.

In this section we continue to consider a well-stirred liquid so that the temperature is uniform within the liquid. Heat loss to the surrounding region will given by Newton's law of cooling. Here we assume rapid cooling is taking place.

Application to Rapid Cooling. At the end of the previous section we presented a table for the coffee cup problem where c = .0162. Both the Euler and Euler-Trapezoid algorithms converged but at the different predicted rates. Consider f(t,u) = c(usur - u) where c is about 25 times larger than the c in the coffee cup problem, say, c =.405. If h = 5, then hc = 2.025, |1 - hc| > 1, and Euler's algorithm will blowup. This is illustrated by the following figure where the computed data points have been connected by chords. The Euler-Trapezoid algorithm will not blowup, and in fact, the errors are relatively small.

Figure: Euler Algorithm: Blowup with c = .405


2.5.3.   Model.

The model is from Newton's law of cooling. Let u(t) be the temperature of the liquid.

ut = c(usur - u) and u(0) given.

The constant c determines how fast heat is leaving the container. For an insulated cup c will be relatively small. If the cup is made of metal, c will be larger. Further, if the cup is metal and there is a large breeze, then c will be even larger.


2.5.4.   Method.

The Euler-Trapezoid algorithm, which can compute the solution of stiff differential equations with second order accuracy, is based on the trapezoid rule for numerical integration. Note, ut = f(t,u) can be written as

The discrete form of this is

Observe the right side where the unknown uk+1 also appears. This is an additional complication relative to Euler's algorithm. In a previous section we studied the bisection algorithm which was used to find roots. There are two other root finding methods which we will study in the next two sections. For the present we will use a Maple procedure called fsolve to find the unknown.

There are two important differences between the Euler algorithm and the Euler-Trapezoid algorithm. First, the Euler algorithm has an error bound which is proportional to h; where as, the Euler-Trapezoid algorithm has an error bound which is proportional to h2 . Second, in the case that fu is negative the error bound for the Euler-Trapezoid algorithm is valid for all k and not just those between 1 and K with h = T/K. This is particularly important when fu is a large negative number.

  Euler-Trapezoid Algorithm.

        choose h
	u0 = u(0)
	for k = 1,maxk
		oldf = f(k*h,u(k) )
		solve for newu = u(k) + (h/2)*(oldf + f((k+1)*h,newu))
		u(k+1) = newu
	endloop.


2.5.5.   Implementation.

This is a modified version of the Maple code for the Euler algorithm to the Euler-Trapezoid algorithm. We have used the Maple procedure fsolve to solve the nonlinear problem associated with each time step. The first graph is for the same nonstiff data that was used in the Euler implementation in the previous section. We have also used a variety of mesh sizes. Note the Euler-Trapezoid algorithm has converged much more rapidly than the Euler algorithm.

Maple Code for the Euler-Trapezoid Algorithm.

  Input Data:
        > t:='t':
        > u:='u':
        > f:=(t,u)->.061*(70 - u);
		
        
        > t0:=0:
        > u0:=200:
        > T:=50:
        > K:=10:

  Procedure EULERT is Defined:
        > EULERT:=proc(f,t0,u0,T,K)
        > t(0):= t0:
        > h:=T/K:
        > u(0):= u0:
        > for k from 0 to K do
        >    oldf:=f(t(k),u(k)):
        >    t(k+1):= t(k) + h:
        >    fsolve(x=u(k) + (h/2)*(oldf + f(t(k+1),x)),x):
        >    u(k+1):=x:
        > od:
        > end:

  Output Data:
        > with(plots):
        > EULERT(f,0,200,50,4):
        > L:=[seq([t(n),u(n)],n=0..4)]:
        > EULERT(f,0,200,50,8):
        > LL:=[seq([t(n),u(n)],n=0..8)]:
        > EULERT(f,0,200,50,16):
        > LLL:=[seq([t(n),u(n)],n=0..16)]:
        > plot({L,LL,LLL},x=0..50);

Figure: Euler-Trapezoid Solutions

Next we try some stiff data that was reported earlier where c = .405 and with variable mesh h = 5 (K = 10), 2.5 (K = 20), and 1.25 (K = 40). Later we shall use an alternate method for finding the fixed point. .

Figure: Solution of Stiff Equation

The next computations are done using Matlab, and we illustrate the more rapid convergence of the Euler-Trapezoid algorithm for the differential equation from Newton's law of cooling where usur = 70.0 and c = 1.0 . In this case, the solve step within the algorithm is a simple linear equation whose solution is easy to find:

newu = u(k) + (h/2)*(oldf + f((k+1)*h,newu))

= u(k) + (h/2)*(c*(usur - u(k)) + c*(usur - newu)).

Solve for newu = (u(k) + (h/2)*(c*(usur - u(k)) + c*usur))/(1 + c*h/2).

The numerical errors for different numbers of steps, kk (h = dt = T/kk), are computed at time equal to 1.0, and the reader should compare the following figure of the Euler-Trapezoid error with figure in the previous section for the Euler error.

Matlab Code for Newton's Law of Cooling.

        clear;
        i=0;
        vec = zeros(12,1);
        vect = zeros(12,1);
        vecdt= zeros(12,1);
        for kk=4:4:48
            T  = 1.0;
            dt = T/kk;
            u0 = 200.;
            c  = 1.0;
            usur  = 70.;
            uk  = u0;
            ut  = u0;
            for k = 1:kk
                uk = uk +dt*c*(usur -uk);
                uex = usur + (u0 -usur)*exp(-c*k*dt);
                ut = (ut +dt*c*usur - dt*c*ut/2)/(1+c*dt/2);
                error = abs(uk - uex);
                errort = abs(ut - uex);
            end
            i = i+1;
            vect(i) = errort;
            vec(i) = error;
            vecdt(i) = 1/dt;
        end
        plot(vecdt,vect)

Figure: Euler-Trapezoid Error versus Steps


2.5.6.   Assessment.

We now give the discretization error analysis for the special case of Newton's law of cooling where f(t,u) = c(usur - u). This analysis is very similar to the Euler algorithm analysis, and we will also first use the extended mean value theorem

.

Now use the mean value theorem

u((k+1)h) = u(kh) + ut (ck+1 )h.

Solve for u(kh) and insert it into the above.

(1)

At this point we again use the backward substitution

Assume and use the fact that a < 1 to conclude

(2)

Euler-Trapezoid Error Theorem. Consider the Euler-Trapezoid algorithm as it is applied to f(t,u) = c(usur - u) and c > 0. Let h be fixed and assume .

If the first and second derivatives are bounded, and M and a are defined as in (1), then (2) must hold for all k.


2.5.7.   Homework.

  1. Write a computer program for the Euler-Trapezoid algorithm and verify the computations in the table of the previous lecture.

  2. In the proof of the error estimate in (2) complete all the steps between the inequalities (1) and (2).

  3. Solve the stiff equation that models the speed of a unit mass which is subject to gravitational force, 32, and resistance of the medium , -.5u 2, where u is the speed. Then the differential equation is

    ut = 32 - .5u2 and u(0) = 200.

  4. Use the Euler-Trapezoid algorithm to approximate the solution to the problem in 3. You may have to adjust the use of fsolve.