239
239
```math
240
240
I = \i nt_0^1 e^x\, dx = e - 1
241
241
```
242
- which is approximately $(exact).
242
+ which is approximately $(round( exact; digits=7) ).
243
243
244
244
We consider a sequence of results where we double the number of integration points:
245
245
"""
@@ -319,7 +319,7 @@ md"""
319
319
## Simpson's rule
320
320
"""
321
321
322
- # ╔═╡ fb9420e4-d49c-4cfe-b029-c3a0e92f9af2
322
+ # ╔═╡ becdcc4e-ecff-46ad-8f3a-92d117e374f7
323
323
md """
324
324
Considering the construction of the trapezoidal rule
325
325
we may easily wonder: why stop at using only linear polynomials
@@ -340,11 +340,27 @@ This is a little harder to compute and will be done as an exercise. The resultin
340
340
&= \f rac h6 f(t_0) + \f rac h3 \s um_{i=1}^{n-1} f(t_i) + \f rac {2h}3 \s um_{i=0}^{n-1} f(m_i) + \f rac h6 f(t_n).
341
341
\e nd{aligned}
342
342
```
343
+ """
344
+
345
+ # ╔═╡ 5ee0ec01-54c3-48d8-8ba8-4460144002dd
346
+ md """
343
347
While a little harder to see, this formula can also be brought into the form of (2):
344
348
it employs **$2n + 1$ equispaced nodes**
345
349
--- namely the collection of both the $t_i$ for $i=0, \l dots, n$ *and* the $m_i$ for $i=0,\l dots n-1$.
346
350
Therefore $N = 2n$ in (2) leading to a **nodal distance** of $\f rac{b-a}{2n} = \f rac{h}{2}$, where we used that $h = t_{i+1} - t_i = \f rac{b-a}{n}$
351
+ """
352
+
353
+ # ╔═╡ abcafa59-e8a1-4438-9ff6-3e8fc9fbd28d
354
+ md """
355
+ !!! exercise
356
+ Derive Simpson's rule, i.e. show that
357
+ ```math
358
+ \i nt_a^b p_{2,h}(x)\, dx = \s um_{i=1}^n \f rac h6 \b ig( f(t_{i-1}) + 4f(m_{i-1}) + f(t_i) \b ig)
359
+ ```
360
+ """
347
361
362
+ # ╔═╡ 277ec8d1-949b-457a-8c1a-12d357a76efc
363
+ md """
348
364
A Julia implementation of Simpson's rule is given below:
349
365
"""
350
366
@@ -437,7 +453,6 @@ into error contributions from each of the intervals $[t_{i-1}, t_i]$.
437
453
Assume for simplicity that the function $f$ is smooth and we can thus
438
454
build a Taylor expansion
439
455
```math
440
- \t ag{5}
441
456
f(x) = \s um_{k=0}^\i nfty \f rac{1}{k!} f^{(k)}(m_i) \, (x-m_i)^k
442
457
```
443
458
around the midpoint $m_i = \f rac{t_{i+1} + t_i}{2}$ of the interval $[t_i, t_{i+1}]$.
@@ -475,6 +490,7 @@ h\, \sum_{i=0}^1 w_i \, q_k(t_i)
475
490
The difference between these expressions is exactly the error
476
491
contribution from the interval $[t_{i}, t_{i+1}]$, namely
477
492
```math
493
+ \t ag{5}
478
494
\b egin{aligned}
479
495
\i nt_{t_i}^{t_{i+1}} f(x)\, dx - Q_{t_i}^{t_{i+1}}(f)
480
496
&= \s um_{k=0}^\i nfty \f rac{1}{k!} f^{(k)}(m) \l eft[ \i nt_{t_i}^{t_{i+1}} q_k(x) - Q_{t_i}^{t_{i+1}}(q_k) \r ight].
@@ -505,13 +521,13 @@ One property of quadrature formulas is their **degree of exactness**:
505
521
but not for $s = r+1$.
506
522
"""
507
523
508
- # ╔═╡ ca54c435-1a49-48e6-9fc9-d0f5a0fe12a4
524
+ # ╔═╡ bc2043be-41e0-4083-9f8b-82b3ce6a13af
509
525
md """
510
526
Note that the polynomial $q_k = ( x - m_i )^{k}$
511
527
only features monomials $x^s$ with $0 \l eq s \l eq k$.
512
528
Therefore a formula with degree of exactness $r$ will have
513
529
$\i nt_{t_i}^{t_{i+1}} q_k(x) - Q_{t_i}^{t_{i+1}}(q_k) = 0$ for $k \l eq r$.
514
- The first non-zero error term is thus
530
+ In (5) the first non-zero error term is thus
515
531
```math
516
532
\b egin{aligned}
517
533
\l eft|\i nt_{t_i}^{t_{i+1}} q_{r+1}(x) - Q_{t_i}^{t_{i+1}}(q_{r+1})\r ight|
@@ -522,20 +538,27 @@ The first non-zero error term is thus
522
538
```
523
539
where in $(\a st)$ all powers in $x$ less than $r+1$ drop again because of $Q$'s degree of exactness and in $(\S )$ we skipped a few non-trivial steps,
524
540
which are optional and will be presented below.
541
+ This is also the leading-order error term, such that
542
+ ```math
543
+ \l eft|\i nt_{t_i}^{t_{i+1}} f(x)\, dx - Q_{t_i}^{t_{i+1}}(f)\r ight| ≤ \w idetilde{C}_i h^{r+2}
544
+ ```
545
+ """
525
546
526
- We thus note that the individual intervals converge with $(r+2)$-th order,
547
+ # ╔═╡ 9cb44731-9d50-4718-9d4d-8fffca3a387f
548
+ md """
549
+ The error in each of the the $N$ subintervals thus converges with $(r+2)$-th order,
527
550
such that combining with (4) and using the triangle inequality
528
551
we obtain the total error as
529
552
```math
530
553
\b egin{aligned}
531
554
\l eft|\i nt_a^b f(x)\, dx - Q_a^b(f)\r ight|
532
555
&\l eq \s um_{i=0}^{N-1} \l eft|\i nt_{t_i}^{t_{i+1}} f(x)\, dx - Q_{t_i}^{t_{i+1}}(f)\r ight|\\
533
- &\l eq h^{r+2} \u nderbrace{\s um_{i=0}^{N-1} \t ilde {C}_i}_\t ext{$N$ terms}\\
534
- &\l eq h^{r+1} \f rac{b-a}{N} N \, \m ax_i \t ilde {C}_i \\
556
+ &\l eq h^{r+2} \u nderbrace{\s um_{i=0}^{N-1} \w idetilde {C}_i}_\t ext{$N$ terms}\\
557
+ &\l eq h^{r+1} \f rac{b-a}{N} N \, \m ax_i \w idetilde {C}_i \\
535
558
&= C \, h^{r+1}
536
559
\e nd{aligned}
537
560
```
538
- where $C = (b-a) \m ax_i \t ilde {C}_i$.
561
+ where $C = (b-a)\, \m ax_i \w idetilde {C}_i$.
539
562
540
563
We notice:
541
564
"""
@@ -768,7 +791,7 @@ this scheme is able to **increase the convergence order**.
768
791
769
792
# ╔═╡ 15b22584-5f21-4f00-ac04-0643fb1dfd56
770
793
md """
771
- Let us apply this to the trapezoidal formula for approximating the integral $I = \i nt_a^b f(x)\, dx$. We use $n+1$ quadrature nodes of equal separation $h = (b-a)/n$.
794
+ Let us ** apply this to the trapezoidal formula** for approximating the integral $I = \i nt_a^b f(x)\, dx$. We use $n+1$ quadrature nodes of equal separation $h = (b-a)/n$.
772
795
As we have discussed above the trapezoidal formula is of order $2$,
773
796
so the leading-order error term is $h^2$.
774
797
However, in this fortunate case one can even show
@@ -1045,7 +1068,7 @@ md"Finally, we perform one more level of extrapolation to get the sxth-order acc
1045
1068
R80 = (16 S80 - S40) / 15
1046
1069
1047
1070
# ╔═╡ cf6e7935-268e-458a-990a-39432ab3e9f3
1048
- md " We compute all errors to 6 digits:"
1071
+ md " We compute all errors to 10 digits:"
1049
1072
1050
1073
# ╔═╡ cc54215f-3af2-48c0-83ec-04cc786fd2ce
1051
1074
begin
@@ -2449,7 +2472,10 @@ version = "1.4.1+2"
2449
2472
# ╟─f189cf70-d72e-483c-af61-a3346ddd201d
2450
2473
# ╟─5f0178ad-c05b-4ac4-a008-b35d105cc7b2
2451
2474
# ╟─c31c7012-6986-441f-ae99-5e2bb2b469e5
2452
- # ╟─fb9420e4-d49c-4cfe-b029-c3a0e92f9af2
2475
+ # ╟─becdcc4e-ecff-46ad-8f3a-92d117e374f7
2476
+ # ╟─5ee0ec01-54c3-48d8-8ba8-4460144002dd
2477
+ # ╟─abcafa59-e8a1-4438-9ff6-3e8fc9fbd28d
2478
+ # ╟─277ec8d1-949b-457a-8c1a-12d357a76efc
2453
2479
# ╠═538b816c-5cc3-4e5c-b259-33825bdc39c3
2454
2480
# ╟─a255138c-74bd-4aad-b49a-0a16746f3bda
2455
2481
# ╠═df5373cc-b997-4a80-906a-9bde0689c84b
@@ -2458,7 +2484,8 @@ version = "1.4.1+2"
2458
2484
# ╟─adf895be-b9d1-40e1-9c2b-146b30b996be
2459
2485
# ╟─4144570b-f8d9-49c8-af6b-732966864755
2460
2486
# ╟─7812f9d7-cda7-4d05-a800-3f7bea2e0e8c
2461
- # ╟─ca54c435-1a49-48e6-9fc9-d0f5a0fe12a4
2487
+ # ╟─bc2043be-41e0-4083-9f8b-82b3ce6a13af
2488
+ # ╟─9cb44731-9d50-4718-9d4d-8fffca3a387f
2462
2489
# ╟─4a048166-315d-4bf6-b099-866c9e3f8813
2463
2490
# ╟─9bad55de-c2d7-44f9-9478-7b66751bfbfe
2464
2491
# ╟─a4cf020a-bb95-4fed-ad50-11ebae1934f5
0 commit comments