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

Chapter 5

Mathematica code for exercises in section 5.1

2.

sum((-1)^floor(2/3*k+4/3)/(2^(k-1)),k = 1 .. n)

> Sum01 := n -> evalf(sum((-1)^floor(2/3*k+4/3)/(2^(k-1)),k = 1 .. n),10) ;

> seq([10*n, Sum01(10*n)], n=1..10);

4.

sum((24*k-11)/(8*k-7)/(8*k-3)/(4*k-1),k = 1 .. n)

> Sum02 := n -> evalf(sum((24*k-11)/(8*k-7)/(8*k-3)/(4*k-1),k = 1 .. n),10) ;

> seq([100*n, Sum02(100*n)], n=1..10);

> Sum02(10000);

5.

The first command factors the sum of three reciprocals:

> factor(1/(4*k-1)-1/(8*k+1)-1/(8*k+5));

6/5-sum((11+40*k)/(4*k-1)/(8*k+1)/(8*k+5),k = 1 .. n)

> Sum03 := n -> 6/5-evalf(sum((11+40*k)/(4*k-1)/(8*k+1)/(8*k+5),k = 1 .. n),10) ;

> seq([100*n, Sum03(100*n)], n=1..10);

> Sum03(10000);

7.

The following program uses the algorithm described in section 5.1. i counts the number of the term that is about to be added, sum keeps track of the current partial sum, odd keeps track of the number of the next odd summand that can be added, even keeps track of the number of the next even summand that can be added, list is the list of the summands that have been added so far.

> riemann1 := proc(target,n)    

> local odd,even,sum,i,l;

> sum:=0; i:=1; odd:=1; even:=2; l:=[];

> while i <= n do

> while sum < target do

> sum := evalf(sum+1/odd,10);

> l :=[op(l),1/odd];

> odd := odd+2; i := i+1;

> end do;

> while sum >= target do

> sum := evalf(sum - 1/even,10);

> l := [op(l),-1/even];

> even := even+2; i := i+1;

> end do;

> end do;

> print(l);

> print(sum);

> end proc;

> riemann1(1.5,200);

> riemann1(.5,200);

8.

See the explanation of this code in the previous program.

> riemann2 := proc(target,n)    

> local odd,even,sum,i,l;

> sum:=0; i:=1; odd:=1; even:=3; l:=[];

> while i <= n do

> while sum < target do

> sum := evalf(sum+1/odd,10);

> l :=[op(l),1/odd];

> odd := odd+4; i := i+1;

> end do;

> while sum >= target do

> sum := evalf(sum - 1/even,10);

> l := [op(l),-1/even];

> even := even+4; i := i+1;

> end do;

> end do;

> print(l);

> print(sum);

> end proc;

> riemann2(1.5,200);

> riemann2(.5,200);

Mathematica code for exercises in section 5.2

1.

x^2*sum((1-x^2)^(k-1),k = 1 .. n)

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

> plots[display](plot(FSum01(3,x),x = -1 .. 1,view = 0 .. 1),plot(FSum01(6,x),x = -1 .. 1,view = 0 .. 1),plot(FSum01(9,x),x = -1 .. 1,view = 0 .. 1),plot(FSum01(12,x),x = -1 .. 1,view = 0 .. 1));

2.

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

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

> seq([10*n, FSum02(10*n,1/10)], n=1..10);

> seq([10*n, FSum02(10*n,1/100)], n=1..10);

> seq([10*n, FSum02(10*n,1/1000)], n=1..10);

3.

sum((x+x^3*(k-k^2))/(1+k^2*x^2)/(1+(k-1)^2*x^2),k = 1 .. n)

> FSum03 :=  (n, x) -> evalf(sum((x+x^3*(k-k^2))/(1+k^2*x^2)/(1+(k-1)^2*x^2),k = 1 .. n),20) ;

> seq([10*n, FSum03(10*n,1/10)], n=1..10);

> seq([10*n, FSum03(10*n,1/100)], n=1..10);

> seq([10*n, FSum03(10*n,1/1000)], n=1..10);

Mathematica code for exercises in section 5.3

4.

2*sum((-1)^k*sin(1/2*(2*k-1)*Pi*x),k = 1 .. n)

> FSum04 :=  (n, x) -> 2*sum((-1)^k*sin(1/2*(2*k-1)*Pi*x),k = 1 .. n) ;

> plots[display](plot(FSum04(5,x),x = -4 .. 4),plot(FSum04(13,x),x = -4 .. 4),plot(FSum04(27,x),x = -4 .. 4));

5.

sum(x^2*sin(x)/(1+k*x^2)/(1+(k-1)*x^2),k = 1 .. n)

> FSum05 :=  (n, x) -> evalf(sum(x^2*sin(x)/(1+k*x^2)/(1+(k-1)*x^2),k = 1 .. n),10) ;

> seq([100*n, FSum05(10*n,Pi/6)], n=1..10);

> seq([100*n, FSum05(10*n,Pi/4)], n=1..10);

> seq([100*n, FSum05(10*n,Pi/2)], n=1..10);

6.

Be certain to  enter  the definition of FSum05(n,x) in exercise 5.

> plots[display](plot(FSum05(3,x),x = -Pi .. Pi),plot(FSum05(6,x),x = -Pi .. Pi),plot(FSum05(9,x),x = -Pi .. Pi),plot(FSum05(12,x),x = -Pi .. Pi));

10.

sum(k*x*exp(-k*x^2)-(k-1)*x*exp((-k+1)*x^2),k = 1 .. n)

exp(x) is the same as E^x.

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

> plots[display](plot(FSum06(5,x),x = -1 .. 1),plot(FSum06(10,x),x = -1 .. 1),plot(FSum06(20,x),x = -1 .. 1));