The Maple notebook is chapter2.mw but you are warned that it may download as a text file.

Chapter 2

Maple code for exercises in section 2.1

7.

The following Maple command allows you to explore the values of the alternating harmonic series when you rearrange summands. It takes three arguments: n, r, and s, which must be positive integers. It returns a decmial approximation to the partial sum of the first n(r+s) terms of the rearranged series that alternates the next r positive summands followed by the next s negative summands.

 > Rearrange := (n, r, s) -> sum(1/(2*k-1),k = 1 .. n*r)-sum(1/2/k,k = 1 .. n*s);

To get the desired accuracy, you need to set the number of digits to at least 20. For example, in part (b) where you are asked to evaluate the partial sums of the rearranged series that alternate two positive tersm followed by a single negative term, the following command evaluates the partial sum of the first 300 terms with 20-digit accuracy.

 > evalf(Rearrange(100,2,1),20);

The exponential function can be evaluated either using E^.. or the function Exp[..].

 > evalf(exp(2*Rearrange(1000000,2,1)),20);

8.

The following Maple command allows you to explore the values of the alternating sum of reciprocals of perfect squares when you rearrange summands. It takes three arguments: n, r,and s, which must be positive integers.It returns a decmial approximation to the partial sum of the first n(r+s) terms of the rearranged series that alternates the next r positive summands followed by the next s negative summands.

 > Rearrange2 := (n, r, s) -> sum(1/(2*k-1)^2,k = 1 .. n*r)-sum(1/4/k^2,k = 1 .. n*s);

Maple code for exercises in section 2.2

8.

The following Maple command allows you to explore the values of the alternating geometric series of reciprocals of powers of 2 when you rearrange summands. It takes three arguments: n, r,and s, which must be positive integers.It returns a decmial approximation to the partial sum of the first n(r+s) terms of the rearranged series that alternates the next r positive summands followed by the next s negative summands.

 > RearrangeGS := (n, r, s) -> sum(1/(2^(2*k-2)),k = 1 .. n*r)-sum(1/(2^(2*k-1)),k = 1 .. n*s);

9.

Try the command

 > int(x^n/(1-x),x);

To find out what this answer means, you can query Maple:

 > ?LerchPhi

Maple code for exercises in section 2.3

7.

The sum of the first n terms of the power series for the arctangent function is given by

 > ArcTanPS := (n, x) -> sum((-1)^k*x^(2*k+1)/(2*k+1),k = 0 .. n-1);

12.

Partial sums of the binomial series for (1+x)^a can be calculated with the following Maple command

 > Binom := (a, n, x) -> 1+sum(binomial(a,m)*x^m,m = 1 .. n);

 > map(Binom,[-2, -.4, 1/3, 3, 5.2],100,.5);

13.

 > f:=x->Binom(.5,100,x);map(f,[-2, -1, .9, .99, 1, 1.01, 1.1]);

 >

14.

The following command plots each of the polynomial approximations against the graph of Sqrt[1+x] and then superimposes all of the graphs.

 > plots[display](plot([sqrt(1+x), Binom(1/2,2,x)],x = -1 .. 2,view = 0 .. 2.5),plot([sqrt(1+x), Binom(1/2,5,x)],x = -1 .. 2,view = 0 .. 2.5),plot([sqrt(1+x), Binom(1/2,8,x)],x = -1 .. 2,view = 0 .. 2.5),plot([sqrt(1+x), Binom(1/2,11,x)],x = -1 .. 2,view = 0 .. 2.5));

Maple code for exercises in section 2.4

4.

Partial sums of the power series for ln(1+x) can be calculated with the following Maple command

 > LogSeries :=  (n, x) -> sum((-1.)^(k-1)*x^k/k,k = 1 .. n);

 > g:= x -> LogSeries(100,x);map(g,[-.9, .9, .99, .999, 1, 1.001, 1.01, 1.1]);

5.

Partial sums of Gregory's series for ln(1+x) can be calculated with the following Maple command

 > Gregory :=  (n, x) -> 2*sum((x/(x+2))^(2*k-1)/(2*k-1),k = 1 .. n);

 > evalf(Gregory(10,4),10);

 > evalf(Gregory(10,-4/5),10);

 > evalf(ln(5),10);

6.

 > h:=x -> Gregory(100,x);evalf(map(h,[-.9, .9, 1, 1.1, 5, 20, 100]),20);

 >

7.

The sum of the first thousand terms of this series can be calculated with the following Maple command

 > evalf(sum((-1)^(1/2*(k-1)*(k-2))/k,k = 1 .. 1000),20);

9.

The sum of the first thousand terms of the series for gamma can be calculated with the following Maple command

 > evalf(sum((-1)^k*Zeta(k)/k,k = 2 .. 1000),10);

 > evalf(gamma,10);

13.

The sum of the first thousand terms of this series can be calculated with the following Maple command

 > evalf(sum(1/sqrt(k),k = 1 .. 1000),10);

17.

 > evalf(floor(exp(100-gamma)),50);

Maple code for exercises in section 2.5

1.

The functions used in this exercise are tan(x), arctan(x), sec(x), ln(x), arcsec(x), and  tanh(x). The  command eval(diff(f(x),x\$n),x=a), evaluates the nth derivative of f at x = 0. The next command creates a table of the values of the first through 10th deriviatives of tan(x) evaluated at x = 0.

 > d := (n,f,a) -> eval(diff(f(x),x\$n),x=a);

 > map(d,[1,2,3,4,5,6,7,8,9,10],tan,0);

2.

The polynomial approximation to tan(x) using the first five non-zero terms is

 > P5Tan := x -> x+2*x^3/3!+16*x^5/5!+272*x^7/7!+7936*x^9/9!;

The following commmand plots both the tangent function and the polynomial approximation.

 > plot([tan(x), P5Tan(x)],x = -1/2*Pi .. 1/2*Pi, y=-10..10);

7.

Partial sums of the binomial series for (1+x)^a can be calculated with the following Maple command

 > Binom := (a, n, x) -> 1+sum(binomial(a,m)*x^m,m = 1 .. n);

The list of values of the partial sums can be generated with the following Table command

 > seq([100*n, Binom(-.5,100*n,200/199)],n = 1 .. 10);

You can plot these values with the command

 > plots[listplot]([seq([100*n, Binom(-.5,100*n,200/199)],n = 1 .. 10)],style = POINT,symbol = CIRCLE);

8.

 > seq([100*n, Binom(-.5,100*n,1)],n = 1 .. 10);

 > seq([100*n, Binom(-.5,100*n,-1)],n = 1 .. 10);

12.

Enter the definition of the following function

 > Binom := (a, n, x) -> 1+sum(binomial(a,m)*x^m,m = 1 .. n);

The two values that you need to compare are

 > [Binom(.5,299,200/199), evalf(sqrt(399/199))];

Their difference is

 > Binom(.5,299,200/199)-evalf(sqrt(399/199));

The 300th derivative of sqrt(1+x) is

 > diff(sqrt(1+x),x\$300);

The error term given by Lagrange's remainder theorem is

 > ErrorBound := c ->abs( eval( diff( sqrt(1+x), x\$300 ), x=c ) )*(200/199)^300 / 300!;

 > plot(ErrorBound(c),c = 0 .. 200/199, y=0..0.00005);

What is the value of c on the interval [0 , 200/199] that maximizes the error and what is the resulting bound on the error?

16.

Enter the definition of the following function

 > Binom :=  (a, n, x) -> 1+sum(binomial(a,m)*x^m,m = 1 .. n)

Define a new error bound function for x = 1 that depends on the choice of a. Note that that the value of c that maximizes these errors is c = 0.

 > ErrorBound := (a,n) ->  abs( eval( diff( (1+x)^a, x\$n ), x=0 ) )/ n!;

 > map(ErrorBound,[-1, -.8, -.6, -.6, 0, .2, .4, .5],100);

20.

The following command plots the three functions. You should be able to determine which is which by their values at x = 0.

 > plot([eval(diff(ln(1+y),y\$7)/7!,y = 0), eval(diff(ln(1+y),y\$7)/7!,y = x), ln(1+x)-x+1/2*x^2-1/3*x^3+1/4*x^4-1/5*x^5+1/6*x^6],x = 0 .. 1,color=[red,green,blue]);

 >