Chapter 6

173 days ago by MichaelDeveau

Chapter 6

6.1.8

reset() def a(k): if k == 0: return 1/2*integral(x^2, (x, -1, 1)); else: return integral(x^2*cos(k*pi*x), (x, -1, 1)); b(k) = integral(x^2*sin(k*pi*x), (x,-1,1)); 
       

6.1.11

The list shows the order in which the summands have been rearranged.

Thus, with x = 0.5, we take the first summand, then the fourth, then the second, then the seventh, and so on.

reset() def riemann(x): var('j'); pos = []; neg = []; negi = 0; posi = 0; k = 1; l = []; s = 0; posl = []; negl = []; summands = [(-1)^(j-1)*cos((2*j-1)*x)/(2*j-1) for j in [1..100]]; for j in [1..100]: if summands[j-1] >= 0: pos.append(summands[j-1]); posl.append(j); else: neg.append(summands[j-1]); negl.append(j); while k <= 20: while s < 1: s += pos[posi]; l.append(posl[posi]); posi += 1; k += 1; while s >= 1: s += neg[negi]; l.append(negl[negi]); negi += 1; k += 1; print(l); print(s); riemann(0.5); 
       
[1, 4, 2, 7, 3, 10, 13, 16, 5, 6, 19, 22, 24, 25, 8, 27, 28, 30, 9, 31,
33, 34, 36, 37, 11]
0.981604639908980
[1, 4, 2, 7, 3, 10, 13, 16, 5, 6, 19, 22, 24, 25, 8, 27, 28, 30, 9, 31, 33, 34, 36, 37, 11]
0.981604639908980

6.1.13

The following command will calculate a numerical approximation to the value of the integral.

reset() var('u'); def F(n): return N(numerical_integral(sin((2*n+1)*u)*sqrt(9+2*u)/sin(u), 0, pi/2)[0]/pi); ns = [5,10,..,150]; bns = [F(n) for n in ns]; list_plot(zip(ns,bns)).show(); 
       

6.1.17

You can simplify Sage's answer by using your knowledge that k is an integer and therefore sin(k*pi) = 0 and cos(k*pi) = (-1)^k.

reset() var('k'); def a(k): if k == 0: return 1/2*integral(2*x+1, (x, -pi, 0))/pi + integral(1/3*x-2/3, (x,0,pi))/pi; else: return integral((2*x+1)*cos(k*x), (x, -pi, 0))/pi + integral(1/3*(x-2)*cos(k*x), (x, 0, pi))/pi; def b(k): return integral((2*x+1)*sin(k*x), (x, -pi, 0))/pi + integral(1/3*(x-2)*sin(k*x), (x, 0, pi))/pi; print([a(0), a(k)]); print(b(k)); 
       
[1/2*(pi - pi^2)/pi - 1/6*(4*pi - pi^2)/pi, 1/3*(((pi - 2)*k*sin(pi*k) +
cos(pi*k))/k^2 - 1/k^2)/pi - (((2*pi - 1)*k*sin(pi*k) + 2*cos(pi*k))/k^2
- 2/k^2)/pi]
-1/3*(((pi - 2)*k*cos(pi*k) - sin(pi*k))/k^2 + 2/k)/pi - (((2*pi -
1)*k*cos(pi*k) - 2*sin(pi*k))/k^2 + 1/k)/pi
[1/2*(pi - pi^2)/pi - 1/6*(4*pi - pi^2)/pi, 1/3*(((pi - 2)*k*sin(pi*k) + cos(pi*k))/k^2 - 1/k^2)/pi - (((2*pi - 1)*k*sin(pi*k) + 2*cos(pi*k))/k^2 - 2/k^2)/pi]
-1/3*(((pi - 2)*k*cos(pi*k) - sin(pi*k))/k^2 + 2/k)/pi - (((2*pi - 1)*k*cos(pi*k) - 2*sin(pi*k))/k^2 + 1/k)/pi

6.2.1

reset() def S1(n): var('k'); return sum(k^3/n^4-2*k^2/n^3+k/n^2, k, 0, n-1); print([(n, N(S1(n), digits=10)) for n in [1..20]]); 
       
[(1, 0.0000000000), (2, 0.06250000000), (3, 0.07407407407), (4,
0.07812500000), (5, 0.08000000000), (6, 0.08101851852), (7,
0.08163265306), (8, 0.08203125000), (9, 0.08230452675), (10,
0.08250000000), (11, 0.08264462810), (12, 0.08275462963), (13,
0.08284023669), (14, 0.08290816327), (15, 0.08296296296), (16,
0.08300781250), (17, 0.08304498270), (18, 0.08307613169), (19,
0.08310249307), (20, 0.08312500000)]
[(1, 0.0000000000), (2, 0.06250000000), (3, 0.07407407407), (4, 0.07812500000), (5, 0.08000000000), (6, 0.08101851852), (7, 0.08163265306), (8, 0.08203125000), (9, 0.08230452675), (10, 0.08250000000), (11, 0.08264462810), (12, 0.08275462963), (13, 0.08284023669), (14, 0.08290816327), (15, 0.08296296296), (16, 0.08300781250), (17, 0.08304498270), (18, 0.08307613169), (19, 0.08310249307), (20, 0.08312500000)]

6.2.2

In the argument of ApproxS, we enter the list of points in the partition in increasing order, starting with 0 and ending with 1.

reset() def ApproxS(P): s = 0; for k in range(len(P)-1): s += (P[k]^3-2*P[k]^2+P[k])*(P[k+1]-P[k]); return s; print(ApproxS([0, 0.25, 0.5, 0.75, 1])); print(ApproxS([0, 0.1, 0.35, 0.6, 0.85, 1])); 
       
0.0781250000000000
0.0840875000000000
0.0781250000000000
0.0840875000000000

6.2.3

reset() def S2(n): var('k'); return sum(sin(n/k)/n, k, 1, n-1); print([(n, N(S2(n), digits=10)) for n in [5,10,..100]]); 
       
[(5, 0.3167880893), (10, 0.3644744077), (15, 0.5536658414), (20,
0.4991922040), (25, 0.4968500478), (30, 0.4689565737), (35,
0.4422460773), (40, 0.5494701107), (45, 0.5067383028), (50,
0.4704957807), (55, 0.4908737039), (60, 0.4949523778), (65,
0.5220033391), (70, 0.4816648601), (75, 0.4921396949), (80,
0.5177380149), (85, 0.4866740513), (90, 0.4987324877), (95,
0.4974927432), (100, 0.5059985018)]
[(5, 0.3167880893), (10, 0.3644744077), (15, 0.5536658414), (20, 0.4991922040), (25, 0.4968500478), (30, 0.4689565737), (35, 0.4422460773), (40, 0.5494701107), (45, 0.5067383028), (50, 0.4704957807), (55, 0.4908737039), (60, 0.4949523778), (65, 0.5220033391), (70, 0.4816648601), (75, 0.4921396949), (80, 0.5177380149), (85, 0.4866740513), (90, 0.4987324877), (95, 0.4974927432), (100, 0.5059985018)]

6.2.5

reset() print(integrate(cos(100*pi*x)^2, (x, 0, 1))); def S3(n): var('k'); return sum(cos(100*pi*k/n)^2/n, k, 0, n-1); print([(n, N(S3(n), digits=10)) for n in [1..30]]); 
       
1/2
[(1, 1.000000000), (2, 1.000000000), (3, 0.5000000000), (4,
1.000000000), (5, 1.000000000), (6, 0.5000000000), (7, 0.5000000003),
(8, 0.5000000000), (9, 0.5000000000), (10, 1.000000000), (11,
0.4999999999), (12, 0.5000000000), (13, 0.5000000000), (14,
0.5000000003), (15, 0.5000000000), (16, 0.5000000000), (17,
0.4999999999), (18, 0.5000000002), (19, 0.5000000002), (20,
1.000000000), (21, 0.5000000002), (22, 0.5000000002), (23,
0.4999999998), (24, 0.5000000000), (25, 1.000000000), (26,
0.5000000000), (27, 0.4999999999), (28, 0.5000000003), (29,
0.5000000001), (30, 0.5000000000)]
1/2
[(1, 1.000000000), (2, 1.000000000), (3, 0.5000000000), (4, 1.000000000), (5, 1.000000000), (6, 0.5000000000), (7, 0.5000000003), (8, 0.5000000000), (9, 0.5000000000), (10, 1.000000000), (11, 0.4999999999), (12, 0.5000000000), (13, 0.5000000000), (14, 0.5000000003), (15, 0.5000000000), (16, 0.5000000000), (17, 0.4999999999), (18, 0.5000000002), (19, 0.5000000002), (20, 1.000000000), (21, 0.5000000002), (22, 0.5000000002), (23, 0.4999999998), (24, 0.5000000000), (25, 1.000000000), (26, 0.5000000000), (27, 0.4999999999), (28, 0.5000000003), (29, 0.5000000001), (30, 0.5000000000)]

6.3.15

The first command defines the function ((x)). We then plot it.

The command points(n) generates a table of the approximations to f(x) at the values x = 1/1000, 2/1000, ... , 1. This uses a summation with n summands (and thus an error that is bounded by 1/2n).

reset() def num(x): if x < floor(x) + 1/2: return x - floor(x); elif x == floor(x) + 1/2: return 0; else: return x - floor(x) - 1; plot(lambda x: num(x), (x,-4,4)).show(); def points(n): l = []; for j in [1/1000,2/1000,..,1]: s = 0; for k in [1..n]: s += num(k*j)/k^2; l.append((j, s)); return l; list_plot(points(10)).show(); list_plot(points(100)).show(); list_plot(points(1000)).show(); # This is processing-intensive! 
       






6.3.19

reset() def fun(k,d): if mod(k,d) == 0: return d*(-1)^d; else: return 0; def psi(k): s = 0; for d in [1..k]: s += fun(k,d); return s; print([(k, psi(k)) for k in [1..100]]); 
       
[(1, -1), (2, 1), (3, -4), (4, 5), (5, -6), (6, 4), (7, -8), (8, 13),
(9, -13), (10, 6), (11, -12), (12, 20), (13, -14), (14, 8), (15, -24),
(16, 29), (17, -18), (18, 13), (19, -20), (20, 30), (21, -32), (22, 12),
(23, -24), (24, 52), (25, -31), (26, 14), (27, -40), (28, 40), (29,
-30), (30, 24), (31, -32), (32, 61), (33, -48), (34, 18), (35, -48),
(36, 65), (37, -38), (38, 20), (39, -56), (40, 78), (41, -42), (42, 32),
(43, -44), (44, 60), (45, -78), (46, 24), (47, -48), (48, 116), (49,
-57), (50, 31), (51, -72), (52, 70), (53, -54), (54, 40), (55, -72),
(56, 104), (57, -80), (58, 30), (59, -60), (60, 120), (61, -62), (62,
32), (63, -104), (64, 125), (65, -84), (66, 48), (67, -68), (68, 90),
(69, -96), (70, 48), (71, -72), (72, 169), (73, -74), (74, 38), (75,
-124), (76, 100), (77, -96), (78, 56), (79, -80), (80, 174), (81, -121),
(82, 42), (83, -84), (84, 160), (85, -108), (86, 44), (87, -120), (88,
156), (89, -90), (90, 78), (91, -112), (92, 120), (93, -128), (94, 48),
(95, -120), (96, 244), (97, -98), (98, 57), (99, -156), (100, 155)]
[(1, -1), (2, 1), (3, -4), (4, 5), (5, -6), (6, 4), (7, -8), (8, 13), (9, -13), (10, 6), (11, -12), (12, 20), (13, -14), (14, 8), (15, -24), (16, 29), (17, -18), (18, 13), (19, -20), (20, 30), (21, -32), (22, 12), (23, -24), (24, 52), (25, -31), (26, 14), (27, -40), (28, 40), (29, -30), (30, 24), (31, -32), (32, 61), (33, -48), (34, 18), (35, -48), (36, 65), (37, -38), (38, 20), (39, -56), (40, 78), (41, -42), (42, 32), (43, -44), (44, 60), (45, -78), (46, 24), (47, -48), (48, 116), (49, -57), (50, 31), (51, -72), (52, 70), (53, -54), (54, 40), (55, -72), (56, 104), (57, -80), (58, 30), (59, -60), (60, 120), (61, -62), (62, 32), (63, -104), (64, 125), (65, -84), (66, 48), (67, -68), (68, 90), (69, -96), (70, 48), (71, -72), (72, 169), (73, -74), (74, 38), (75, -124), (76, 100), (77, -96), (78, 56), (79, -80), (80, 174), (81, -121), (82, 42), (83, -84), (84, 160), (85, -108), (86, 44), (87, -120), (88, 156), (89, -90), (90, 78), (91, -112), (92, 120), (93, -128), (94, 48), (95, -120), (96, 244), (97, -98), (98, 57), (99, -156), (100, 155)]

6.4.2

reset() def distance(x): if x <= floor(x) + 1/2: return x - floor(x); else: return floor(x) + 1 - x; plot(lambda x: distance(x), (x,-2,2)).show(); 
       

6.4.3

Notice what happens to the scale on both the x- and y-axes.

def plotF(n): return plot(lambda x: distance(4^n*x)/(4^n), (x,-4^(1-n),4^(1-n))); plotF(2).show(); plotF(3).show(); plotF(4).show(); 
       




6.4.4

Why don't these look any different?

var('k'); def S4(n,x): s = 0; for k in [0,1,..,n]: s += distance(4^k*x)/(4^k); return s; plot(lambda x: S4(2,x), (x, -2, 2)).show(); plot(lambda x: S4(3,x), (x, -2, 2)).show(); plot(lambda x: S4(3,x), (x, -2, 2)).show(); 
       




6.4.11

Notice what happens to the scale on both the x- and y-axes.

reset() var('k'); def S5(n,x): return sum((6/7)^k*cos(7^n*pi*x), k, 0, n); plot(lambda x: S5(1,x), (x, -1, 1)).show(); plot(lambda x: S5(2,x), (x, -1/7, 1/7)).show(); plot(lambda x: S5(3,x), (x, -1/49, 1/49)).show();