Solving equations by successive substitution: The ... - ACS Publications

The theory behind the method of successive substitution and two approaches for considering convergence problems. Keywords (Audience):. Upper-Division ...
0 downloads 0 Views 3MB Size
Solving Equations by Successive Substitution--The Problems of Divergence and Slow Convergence J. G. Eberhart University of Colorado. Colorado Springs, CO 80933

Many of the calculations encountered in physical and analytical chemistry courses require the solution of nonlinear equations or systems of equations. There is a large class of iterative or successive-approximation methods for solving such problems which are readily adaptable to the microcomputer. The better known of these techniques include successive suhstitution, the Newton-Raphson method, linear interpolation (regula falsi), and trial-and-error searches (such as interval bisection). One of the easiest to learn, because familiarity with calculus is not required, is the method of successive substitution (1-7). (This approach is occasionally called the method of iteration.) The use of this method can sometimes he frustrating, however, because its convergence rate is inherently slower than some of the other iterative methods, like the Newton-Raphson method (8).and it often generates diverging rather than converging sequences. The theory behind this method will be briefly outlined here and two approaches will be considered for dealing with convergence prohlems. The first involves the use of alternative forms for the computational algorithm. The second employs Aitken's 62process (9) after every second successive approximation calculation. This process can accelerate the convergence of the successive approximations or, if they are diverging, frequently can generate a converging sequence out of the diverging one. Both of these approaches will he illustrated here with calculations of a chemical reaction equilibrium composition. The approach taken throughout will he to present this powerful, numerical tool in a form easily translated into a computer program. Theory of Succeslve SubsWulion Successive substitution can be applied either to a single equation (1-6) or to systems of simultaneous equations (6, 7). Only the single equation case will be discussed here. The procedure for successive substitution and the techniques for dealing with convergence problems are easily extended t o simultaneous equations. The equation to be solved is written as where the value or values of x that satisfy eq 1are sought. If this nonlinear equation is difficult or impossible to solve algebraically the method of successive substitution suggests that it be rearranged into the form x = F(x)

(2)

Usually eq 1will have the independent variable x appearing in a number of places in f(x) and the transformation to eq 2 involves selecting one of these terms and "solving" for the x contained therein. Once eq 2 is developed, a first approximation or guessxl is made of the root r, and eq 2 is used to provide an algorithm for generating a sequence of successive approximations 11, XZ,x3, . . . ,I., x,+1,. . .which, i t is hoped, will converge on r. These are ohtained by successive substitution into eq 2, which yields

576

Journal of Chemical Education

For some equations this sequence will converge on a root of eq 1while for others i t will diverge. The conditions of convergence for a sequence generated in this fashion can he ohtained by examining the error of each approximation in the sequence

- zn

en = ,-

(6)

From eq 5 i t follows that dx,+, = F'(x,)dx,, where F'(x) = dFIdx. As n becomes large and the errors 6, become small, these differentials provide a good approximation to the errors, and thus Here x, was also replaced by x, where x is in the neighborhood of r and x,. Equation 7 shows that the error of a new approximation, g + l , is approximately proportional to the first power of the error in the previous approximation, E,,. For this reason successive substitution is referred to as a first-order process. In the Newton-Raphson method C,+I is proportional to en2 and the process is second order. Secondorder processes converge more rapidly than first order, but ordinarilv involve more comnutation oer sten and reauire a knowled& of calculus for th&r applic&ion. ' Equation 7 a h provides the condition of convergence for the itenition process. For convergence to occur it is necessary that ( n r l t)r less than lt,l. A necessary condition for convergence is thus that

IF'(x)l < 1

(8)

in thr neighborhood of the nx,t and its approximations. In fact, eq 7 indicates that the ~mullerthe value of F'(xJ. the faster k the convergence. If 0 < F'(x) < 1,then eaih err& has the same sign and the approach of x, to r will he from one direction. If -1 < F'(x) < 0,then the errors will alternate in sign and the x, will approach r with an alternating sequence. Since the value of r is not known when the solution of an equation is begun, and since X I may he very different from r, i t is usually not practical to calculate the value of F'(x) before beginning successive substitution. Ordinarily one simply tries an iteration scheme and observes or tests whether the sequence generated is converging. If the successive approximations to the root converge slowly or diverge then there are two possible remedies to this difficulty. First, a different form of eq 2 is usually possible, because x ordinarily appears in several places in f(x). This change may lower the value of IF'(x)l sufficiently to obtain convergence rather than divergence, or fast convergence rather than slow convergence. A second approach, called Aitken's 62 process (9), can be obtained from eq 7, which suggests that as x, approaches r the ratios of suhsequent errors, rzlfl, ~31~2, . .. approach a constant. Thus, we can write L Z / ~^. 63/62, as well as cZ2 orl, which yields

-

-

Since eq 9 is approximate, i t cannot yield the exact root r from the three successive approximations XI, 12, and x3. Thus, the solution to eq 9 will be called xa, where x4 will ordinarily be superior toxl,xz, and xs in its accuracy. Solving eq 9 then gives or rearranging The denominators in eqs 10 and 11 are similar to secondorder finite differences and give rise to the 6%in the name of this process. If the algorithm for calculating the sequence of successive approximations is taken as repeated use of eqs 3, 4, and 11, rather than repeated use of eq 3, a converging seauence can often he ohtained from a divereine one.. or a rapidly converging sequence obtained from a slowly converaiue one. Thus. an aleorithm consistinr! of two successive ap&oximations f&lowea by one ~ i t k e n e x t r a ~ o l a t i ocan n often remove the frustrations that can he Dart of the method of successive substitution.

- -

A Chemical Example

T o illustrate the use of successive suhstitution and the ways of dealing with divergence or slow convergence, the following chemical equilibrium problem is considered. Suppose that Nz, Hz, and NH3gas are mixed in acontainer in the respective initial amounts of a = 0.5000 mol, b = 0.8000 mol, and c = 0.3000 mol. Further, assume that the temperature of the gas mixture is 298.15 K so that the pressure-scale equilihrium constant is Kp = 6.045 X lo5 atm-2. Finally, the pressure of the mixture is maintained a t P = 0.002430 atm throughout the course of the chemical reaction Nz(g) + 3H2(g)e 2NH3(g)

-

(12)

Find the amounts of Nz, Hz, and NH3 a t equilibrium. If the extent of the reaction a t eauilibrium is E. then the and NHlat equilibrium area