Thompson - Computing for Scientists and Engineers (523188), страница 12
Текст из файла (страница 12)
As is well known, the sum can be expressed in closedform as(3.2)As one way of deriving this very useful result, try the following exercise.Exercise 3.1Use the method of proof by induction to derive (3.2). That is, show that if theformula is assumed to be true for Gn, then it must be true for Gn+1. In order toget the recurrence started show that the result is evidently true for n = 1. nNote that the geometric series is sometimes written in forms other than (3.2).
Forexample, there may be a common multiplier for each term of the series, which justmultiplies the sum by this multiplier. For clarity and effect, in Figure 3.1 we haveassumed a common multiplier of r. Therefore, the series in this figure starts with rrather than with unity.The convergence properties of the geometric series (3.1) are quite straightforward.
If |r| < 1 the series converges as n, otherwise the series diverges.Note that if r = -1 the value of Gn alternates between 0 and +l, so there is no definite limit for large n.3.1 MOTIVATION FOR USING SERIES: TAYLOR’S THEOREM53FIGURE 3.1 Terms (shown by bars) and partial sums (crosses, omitting the leading term ofunity) for the geometric series. Only for multiplier r = 0.6 is the series convergent.Thus we have the geometric series convergence property(3.3)The convergence conditions are quite evident in Figure 3.1.
The series is thereforedeclared to be divergent, even though its value is always finite. A way around thisanomaly is discussed in Exercise 3.3 below.Programming geometric seriesIf you want practice in writing C programs involving series, you should code up andrun the program Geometric Series. This simple program has a function to sumthe geometric series directly, using (3.1), and it also computes the closed form(3.2).
The program does both of these calculations for a range of r values specifiedas input with a fixed value of n.54POWER SERIESPROGRAM 3.1 Geometric series by direct summing and by the closed form.#include#include<stdio.h><math.h>main (){/* Geometric Series */doublermin,dr,rmax,r,Sum,ClosedForm,error;int nterms,kmax;double GeoSum();printf("Gecmetric Series by Summing & Closed. Form\n");nterms; = 2;while ( nterms > 1 ){printf("\n\nInput rmin,dr,rmax,ntermS (nterms<2 to end):\n");scanf("%lf%lf%lf%i",&rmin,&dr,&rmax,&nterms);if ( nterms < 2 ){printf("\nEnd Geometric Series"); exit(O);}kmax = nterms-1;for ( r = rmin; r <= rmax; r = r+dr ){if ( fabs(r) >= 1 ){printf("\n!! Warning: Divergent series |r|=%g >= l",fabs(r));}Sum = GeoSum(r,kmax); /* direct sum of series *//* Formula for sum to nterms terms;uses r to the nterms power */ClosedForm = (l-pow(r,nterms))/(l-r);error = ClosedForm-Sum;printf("\n%g %g %g %g",r,ClosedForm,Sum,error);}double GeoSum(r,kmax)/* Direct sum of geometric series */double r;int kmax;{double term,sum;int k; term = 1; sum = 1; /* initialize terms & sum */3.1 MOTIVATION FOR USING SERIES: TAYLOR’S THEOREM55for ( k = 1; k <= kmax; k++ ){term = r*term;sum= sum+term;return sum;For the benefit of novice C programmers, we now summarize how the programGeometric Series is organized.
Program execution is controlled by the value ofn, which is denoted by nterms in the program. If there are fewer than two termsin the geometic series (3.1), then one has only the leading term of unity, which isscarcely an interesting series. Therefore, if the input value of nterms is less than 2this is used to signal program termination by a graceful exit (parameter zero).
If theseries is to be summed, then there are kmax = n - 1 terms to be added to the starting value of unity.For each value of the multiplier r in the input range, starting at rmin and going up to rmax by steps of dr, the program first checks whether r is beyond therange that leads to convergent series.
Although the series has a definite value forany finite n , it is instructive to see how a warning about nonconvergence can be output. Next, the function GeoSum (about which more is told in the next paragraph) isused to sum the series directly.The formula (3.2) is then coded in-line to produce the value ClosedForm,which requires the C library function pow to compute the power rn . Finally, anydifference between the direct summation and closed-form values is indicated by theirdifference, called error, which is printed following the r value and the two seriesvalues.The function GeoSum, coded after the main program of Geometric Series,involves a simple for loop over the powers of r. The succesive terms are obtained by the recurrence relation indicated, then they are added to the partial sum. Therewill be at least one iteration of the loop, since kmax is at least 1 because nmax is atleast 2.
The value of sum is retumed to the function GeoSum for assignment in themain program.Given this program description, and some nimble fingers, you should be readyto code, test, and use Geometric Series.Exercise 3.2(a) Code the program Geometric Series, listed as Program 3.1, modifyingthe input and output functions for your computing environment. Then test theprogram termination control (nterms < 2) and warning message for |r |1.56POWER SERIES(b) Run the program for a range of values of the multiplier r and the number ofterms nterms, to convince yourself that for a reasonable range of these parameters of the geometric series the direct-summation and closed-form methods giveclose numerical agreement.(c) Examine the convergence of the series for values of r that are close to (butless than) unity in magnitude.
For example, use r = -1 + 10-3, then find outhow large nterms must be in order to get agreement with the infinite seriesvalue of l/(1 - r) to about one part per million. It would be most convenientto modify the program to calculate this value and compare it with the directsummation value. nAlternating seriesAs you will have discovered by working part (c) of Exercise 3.2, series in whichsuccessive terms are of similar magnitude but opposite sign, so-called “alternatingseries,” are particularly troublesome numerically.
The geometric series is particularly convenient for investigating and understanding the problems that can arise withalternating series.For example, suppose that you had to sum the geometric series term by term forr = -1 + , where10-6 and is positive. By looking at the leftmost panel ofFigure 3.1 you would know that the series is convergent but it would clearly takemany terms before the remaining terms could be ignored. Numerically, by thatnumber of terms the roundoff error of your computer may have already overwhelmed the significant digits in your partial sum.Exercise 3.3(a) Suppose that, for a multiplier an amount larger than -1, we wanted to estimate how many terms, k, it takes before a geometric-series term has become 1/2of the first term.
By using (natural) logarithms and the approximation thatIn (1 - )for smallshow that kln(2)/0.7/ . Thus if one had= 10-6, more than one million terms would be needed for even reasonableconvergence.(b) Show that for r = -1 + as the multiplier in the geometric series the algebraic sum of the series is l/(2- ).
Thus show that as0 the sumtends to 1/2, which is just the mean value of the successive partial sums shownon the left side of Figure 3.1, namely 1 and 0.(c) Write down the geometric series for negative r term by term, but expressedin terms of |r|, so that the alternating signs are explicit in the sum. Next factorout the (1 - |r|), sum the remaining series in the geometric form, then divideaway the first factor. Show that the alternating series sums to l/( 1 + |r| ) ,which is l/2 at r = -1, just as in (b). Explain why the two methods agree, andexplain whether a limit process similar to that in (b) is necessary in the secondmethod.
n3.1 MOTIVATION FOR USING SERIES: TAYLOR’S THEOREM57Notice in part (b) of Exercise 3.3 that if r were allowed to approach the limit of-1 before the summation were attempted, then the result would be undefined, asFigure 3.1 shows. Part (b) shows that if the limit is taken after an expression forthe sum has been obtained, then the result is well defined. This peculiarity of thestrong dependence of the series values on the order of taking limits appears again inour investigation in Section 9.6 of the Wilbraham-Gibbs overshoot phenomenon forFourier series.From the example in Exercise 3.3 we see particularly troublesome aspects of alternating series.
Specialized techniques have been developed for alleviating some oftheir troubles, as described in the text by Taylor and Mann. An interesting result oncombining geometric series with multipliers of opposite sign is obtained in the following exercise.Exercise 3.4(a) Show analytically that for a convergent geometric series(3.4)(b) Make a sketch, similar to Figure 3.1, of the terms on the left and right sidesof this equation, Thereby explain the result (3.4). nAnother property of the geometric series that leads to a very interesting result isthe integral of the infinite series (3.1).
In order to produce the result in standardform, and assuming that |r|<1, replace r by -r in (3.1) and (3.2), then integrateboth l/( 1 + r ) and each term of the convergent series in order to produce the seriesexpansion(3.5)If we now identify the indefinite integral on the left-hand side as 1n(1 + r), onehas produced a power series expansion for the natural logarithm. This result agreeswith the Taylor-expansion method of deriving logarithms in series expansion that ispresented in Section 3.2.Exercise 3.5Show the steps leading to the result (3.5) for the power-series expansion of theintegral.
nNow that we have some experience with the well-behaved geometric series, it istime to expand our horizons to power series that are more general. With this as ourgoal, we should review Taylor’s theorem on power-series expansions and functionderivatives.58POWER SERIESTaylor’s theorem and its proofIn later chapters, especially in Chapters 4, 5, 7, and 8, we often require polynomialapproximations to functions. If the function is smooth enough that as many derivatives as needed can be calculated analytically, then Taylor’s theorem gives a uniqueprescription for the polynomial coefficients.
We now review the conditions for applicability of the theorem and we review a convenient proof of it.Suppose that a function y(x) and its first n derivatives y(k)(a) for k = 1,2,..,nare continuous on an interval containing the points a and x. Then Taylor’s theoremstates that(3.6)in which the remainder after n terms, Rn, is given by(3.7)In practice, one tries to choose n and a so that it is a fair approximation that Rn canbe ignored for the range of x of current interest, typically x values near a. If Rn maybe ignored, then y (x) is aproximated by an n th-order polynomial in the variable(x - a). In order to make the statement of Taylor’s theorem plausible, consider thefollowing examples.Exercise 3.6(a) Suppose that y (x) is a polynomial of order n in the variable (x - a), sothat(3.8)Show that Taylor’s theorem, (3.6), is exactly satisfied and that the remainder isidentically zero because the derivative therein is zero.(b) Suppose now that y (x) is a polynomial of order (n + 1) in the variable(x - a).
Show that the remainder after n terms is given by(3.9)which is just the (n + 1) th term of the polynomial. nTherefore, we have two examples in which the theorem is true, but (just as twoswallows do not a summer make) this is not sufficient for a mathematical proof, especially because the result should not depend on the use of a polynomial which has a3.1 MOTIVATION FOR USING SERIES: TAYLOR’S THEOREM59particularly simple dependence on the variable a.