#--------------------------------------------------- Math 1225 Laboratory Assignment #6 March 31, 1999 Treibergs DueApril 14, 1999 #--------------------------------------------------- # INFINITE SUMS To study infinte sums we can look directly at the sequence of partial sums. We create a little loop in which j runs from 1 to 20. We compute the j-th term. In the case of the alternating harmonic series, the j-th term is a_j = (-1)^(j+1)/j. We store this quantity in the variable "term". The variable "SUM" accumulates the partial sums. We initialize "SUM:=0;" before the loop. Then the first partial sum is S_1=a_1 or SUM + a_1. We replace the old SUM by SUM+term. Then the second time through the loop, term = a_2 =-1/2 and S_2=a_1+a_2 = SUM+term. We replace the old SUM by SUM+term. We proceed through all the j's th is way. For alternating series, the error is less than the first term neglected, so "error=1/(j+1);". The alternation is roughly settling in on the midline between the last two partial sums or st:=(S_19+S_20)/2=S_20-a_20/2. To plot the sums, we make a list[[0,0],[1,S_1],[2,S_2],[3,S_3],...,[20,S_20]] by adding a point each time we go through the loop. The list begins with SL:=[[0,0]]. The first time through the loop, we increase the list by one point, adding the coordinate (1,S_1). To add to a list in MAPLE the instruction is SL:=[op(SL),j,SUM] which results in SL now containing the list [0,0,0,1]. The second list being plotted is just the horizontal line connecting the points (0,st) to (21,st). To print out the variable, we are using MAPLE's formatted print. The instruction "printf(str,var1,var2,...);" requires a formatting string "str" and the list of variables "var1,var2,..." to be printed (similar to formatted print in FORTRAN and other languages, see MAPLE help for printf). str contains characters to be printed and placeholders for variables. For example, %3d means an integer variable taking three characters. % 20.10f means a floating point variable taking 20 characters, 10 digits after the decimal place. "\n" means next line. There are other formatting designators for other variable types. > SUM:=0:SL:=[[0,0]]:printf(`Alternating Harmonic Series \n n n-th > term a_n n-th partial sum S_n error bound \n`); > for j from 1 to 20 do; > term:=(-1)^(j+1)/j; > SUM:=SUM+term; > error:=1/(j+1); > SL:=[op(SL),[j,SUM]]; > printf(` %3d % 20.10f % 20.10f %20.10f\n`,j,term,SUM,error);od: > st:=SUM-term/2: > > > plot({SL,[[0,st],[21,st]]},x=0..21,title=`Alternating harmonic > series`,labels=[`n`,`S.n`]); > We plot the running totals of the series. Since signs alternate this time, the sum is increased, or decreased whenever a positive or negative term is added. In case the series has positive terms as in the sum S=sum(1/j^2,j=1..infinity), for example, we replace the line in the program by "term=1/j^2;" . The error this time is found using the integral test. The error = |S-S_n| = sum(1/j^2,j=n+1..infinity). This can be estimated using the integral formula (draw the picture!) |S-S_n| <= int(1/x^2,x=n..infinity) = 1/n. Thus we may write "error=1/n;" . Also "st:=SUM+error;" is the line SUM will never exceed. POWER SERIES MAPLE can manipulate series in several ways. In this section we explore the "powseries" package. > restart:with(powseries): > Power series are a special data structure in MAPLE. It operates slightly differently than other packages. In particular, the output of an instruction might be a procedure that gives the powerseries. Things like composition and division are tremendously tedious to do by hand so we don't mind asking MAPLE to do this for us. The name of a powerseries is declared in "powcreate". For example,if there is a formula for the n-th term then you may define the series using that formula. We let "t" denote the exponential series. > powcreate(t(n)=1/n!,t(0)=1); > The instruction to transform a power series into a standard MAPLEseries structure is "tpsform(t,x,7);" where "t" is the powseries, "x" is the variable and "7" is the order. > tpsform(t,x,7); > # # We can check. > taylor(exp(x),x,7); # Apolynomial can be a powseries: > p:=powpoly(1+x,x):tpsform(p,x,7); > # We can form the power series of the reciprocal. > q:=inverse(p):tpsform(q,x,7); > Suppose we wanted to know the Maclaurin series for f(x)= exp(x)/(1+x). We could compute the Taylor's formula for f(x) or simply multiply the series for exp(x) and for (1+x)^(-1). > f:=multiply(t,q):tpsform(f,x,7); Similarly there are "add", "multconst", "compose", "negative", "powexp", "powlog" , "quotient", "subtract" . Suppose we wanted to find the series for "log(1+x)". One way is to > > l:=powlog(p):tpsform(l,x,7); Another is to observe that log(1+x)=int((1+t)^(-1),t=0..x). Thus > m:=powint(q):tpsform(m,x,7); > # Unfortunately, there is no way to convert a MAPLE series into a MAPLE powseries structure. We know that s(x)=sin(x) satisfies s''=-s, s(0)=0,s'(1)=1, which is enough to define sine. > s:=powsolve(diff(y(x),x,x)=-y(x),y(0)=0,D(y)(0)=1):tpsform(s,x,13); Alternately, we note that the terms satisfy a recursion. See below. > powcreate( v(k)=-v(k-2)/(k*(k-1)), v(0)=0, v(1)=1): tpsform(v,x,13); Another way to specify coefficients of a power series is recursively. Consider the following question from combinatorial geometry. Into how many compartments will n nonparallel lines divide theplane? (no three may intersect in a point!) Let a.n denote this number. a.0=1, a.1=2, a.2=4, a.3=7 and so on. > plots[display]({ > > plot({[[0,6],[10,8]],[[3,10],[7,0]],[[9,10],[3,0]],[[0,0],[0,10],[10,1 > 0],[10,0],[0,0]]}, x=-1.3..13.2,y=-.3..10.3,axes=none), > > plots[textplot]([[2,9,`1`],[5,9,`2`],[9,9,`3`],[2,5,`4`],[5.5,6,`5`],[ > 8,5,`6`],[5.5,1,`7`]]) > },title=`Number of compartments with 3 lines = a.3 = 7`); > How to get a formula for a.n? The trick is to write a recursion formula for the number. The (n+1)st line is cut by the previous n lines into (n+1) pieces. These pieces each cut one of the existing compartments into two, therefore a.(n+1)=a.n + n +1. There are several ways to solve this problem, but we use generating functions. Lets suppose g(x)=a.0 + a.1*x + a.2*x^2 + ... This function is called the generating function. > powcreate(g(n)=g(n-1)+n,g(0)=1):tpsform(g,x,10); Note that g(x)-xg(x)=1+x+2*x^2+3*x^3+...=1+x*diff(1+x+x^2+...,x) =1+x*diff((1-x)^(-1),x) [geometric sum!] =1+x *(1-x)^(-2). Check: > h:=powpoly(1-x,x):k:=multiply(g,h):tpsform(k,x,10); > > taylor(1+x/(1-x)^2,x,10); > > # Thus we may solve for g(x)=(1-x)^(-1) +x*(1-x)^(-3). Check > taylor((1-x)^(-1) +x/(1-x)^3,x,10); > > convert((1-x)^(-1) +x/(1-x)^3,parfrac,x); > But observe that (1-x)^(-1) = (geometric!) = 1 + x + x^2 + ..., diff((1-x)^(-1),x)=(1-x)^(-2) and diff((1-x)^(-1),x,x)=2*(1-x)^(-3) > b:=inverse(h):tpsform(b,x,10); > So bp(x) = sum((n+1)*x^n,n=0..infinity); (which is the same as the more natural sum(k*x^(k-1),k=1..infinity) but we replace n=k-1) > bp:=powdiff(b):tpsform(bp,x,10); > bpp:=powdiff(bp):tpsform(bpp,x,10); > Thus we have a formula for the number of compartments in terms of n. Check: > powcreate(gg(n)=(n^2+n+2)/2):tpsform(gg,x,10); > PROBLEMS 1. a sum(1/j,j=1..infinity); b sum((-1)^(j+1)/(2*j-1),j=1..infinity); c sum(1/j!,j=1..infinity); d sum(1/j^4,j=1..infinity); e sum(0.6^(j-1),j=1..infinity); f sum((-1)^(j+1),j=1..infinity); g sum(sin(evalf(j)),j=1..infinity); 1. Choose three of these sums to analyze. For your three sums, make a table for j=1..20 showing the j-th term a_j and the partial sum S_j. If the sum is convergent, find and explain a bound for the error and tabulate that as well. If it is not convergent, explain why and discuss the behavior of the partial sums. Plot the sequence of partial sums. Discuss your results. 2. Using "powseries", find the Maclaurin series for tan(x) by dividing the powseries for sin(x) by the one for cos(x). Check using "taylor". 3. Using "powseries" find the Maclaurin series for arctan(x) using the fact that arctan(x)=int(1/(1+t^2),t=0..x). Check using "taylor". 4. Using powseries, find the Maclaurin series for cos(sin(x)) by composing cos with sin. Try finding the first three terms by hand! Check using "taylor". 5. (This problem was inspired by Stenberg and Walker, Calculus: A Computer Oriented Presentation, CRICISAM at Florida State University, 1970, p. 955) The Fibonacci sequence satisfies the recursion u.n=u.(n-1)+u.(n-2) where u.0=1 and u.1=1. Thus the first few terms are 1,1,2,3,5,8,13,21,.... The generating function for this sequence is u(x) = u.0+u.1*x+u.2*x^2+... a. Show that the generating function satisfies (1-x-x^2)*u(x) = 1.Check with MAPLE. b. Solve for u(x).Derive the partial fractions expansion u(x)=(b/(1-a*x)-a/(1-b*x))/sqrt(5) where a=(1+sqrt(5))/2 and b= (1-sqrt(5))/2. c. Now expand the two terms in geometric series and equate coefficients to find u.n = ( a^(n+1) -b^(n+1))/sqrt(5). Check d. Show that u.n is the closest integer to a^(n+1)/sqrt(5) andvery nearly equal to this quantity for large n. e. Show that u.99 is approximately 3.5 x 10^20. f. Criticize the derivation of the formula for u.n.