Skip to content

Commit 9e034a1

Browse files
committed
Post-lecture updates
1 parent bac8b01 commit 9e034a1

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

src/05_Interpolation.jl

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ is uniquely defined by the data.
184184

185185
# ╔═╡ 20a76496-f1a0-4690-8522-a13cf4656e6d
186186
md"""
187-
!!! danger "Indexing conventions: Starting at $0$ or $1$"
187+
!!! danger "Indexing conventions: Starting at 0 or 1"
188188
Note that in the definition of the polynomial (Equation (3)) the sum starts now from $j=0$ whereas in equation (1) it started from $j=1$.
189189
190190
When discussing numerical methods (such as here interpolations) it is sometimes more convenient to start indexing from $0$ and sometimes to start from $1$. Please be aware of this and read sums in this notebook carefully. Occasionally we use color to highlight the start of a sum explicitly.
@@ -453,9 +453,29 @@ to obtain an **accurate reconstruction** of the original $f$.
453453
454454
"""
455455

456+
# ╔═╡ 669f818c-8f7c-4e6d-9d89-ea979e69ce66
457+
md"""
458+
A standard metric to measure how good the approximation of $p_n$ to $f$ is,
459+
is to check the largest deviation between the differences of function vaules
460+
on the domain of our data. Assuming we want to approximate $f$ on the interval
461+
$[a, b]$ we thus compute
462+
```math
463+
\max_{x \in [a, b]} | f(x) - p_n(x) | = \|f - p_n\|_\infty,
464+
```
465+
which is the so-called **infinity norm** of the difference $f - p_n$.
466+
More generally the **infinity norm** $\| \phi \|_\infty$ for a function $\phi : D \to \mathbb{R}$ is the expression
467+
```math
468+
\| \phi \|_\infty = \max_{x \in D} |\phi(x)|,
469+
```
470+
i.e. the maximal absolute value the function takes over its input domain $D$.
471+
472+
Note that the error $\|f - p_n\|_\infty$ effectively **measures** how well our **polynomial interpolation model** $p_n$ **generalises to unseen datapoints** $(x_{n+1}, f(x_{n+1}))$ with $x \in D$: If this error $\|f - p_n\|_\infty$ is small, $p_n$ is a very good model for $f$. If this error is large, it is a rather inaccurate model.
473+
"""
474+
456475
# ╔═╡ 5f1abde6-f4fc-4c5e-9a19-abf28ca3584d
457476
md"""
458-
For illustration we contrast two cases, namely the construction of a polynomial interpolation of the functions
477+
We **return to the interpolation problem**.
478+
For illustration in this section we contrast two cases, namely the construction of a polynomial interpolation of the functions
459479
"""
460480

461481
# ╔═╡ b1773d1c-4d3c-4f4b-805d-f188623c9571
@@ -490,13 +510,16 @@ let
490510
titlefontsize=12)
491511
plot!(p, fine, fsin.(fine), label="fsin", lw=2, ls=:dash)
492512
scatter!(p, samples, values_fsin, label="samples")
513+
plot!(p, [-1, 1, 1, -1, -1], [-2, -2, 2, 2, -2]; fill=(0, :grey, 0.1), c=:grey, label="Data domain")
493514

494515
q = plot(fine, poly_fratio.(fine);
495516
label="Polynomial fit", xlims=(-1.3, 1.3), lw=2, ylims=(-0.5, 2),
496517
legend=:topright, title=L"f_{\textrm{ratio}}(x) = 1 / (1 + 20x^2)",
497518
titlefontsize=12)
498519
plot!(q, fratio, label="fratio", lw=2,ls=:dash)
499520
scatter!(q, samples, values_fratio, label="samples")
521+
plot!(q, [-1, 1, 1, -1, -1], [-2, -2, 2, 2, -2]; fill=(0, :grey, 0.1), c=:grey, label="Data domain")
522+
500523

501524
plot(p, q)
502525
end
@@ -535,15 +558,16 @@ To understand this behaviour the following error estimate is useful:
535558
\| \phi \|_\infty = \max_{x \in D} |\phi(x)|,
536559
```
537560
i.e. the maximal absolute value the function takes.
538-
539-
Note that in this theorem the error $\|f - p_n\|_\infty$ effectively measures how badly our polynomial interpolation model $p_n$ generalises for unseen datapoints $(x_{n+1}, f(x_{n+1}))$ with $x \in D$: If this error $\|f - p_n\|_\infty$ is small, $p_n$ is a very good statistical model for $f$. If this error is large, it is a rather inaccurate model.
540561
"""
541562

542563
# ╔═╡ 5f63abce-f843-4c33-9db6-0770323b55ac
543564
md"""
544565
The **key conclusion of the previous theorem** is that
545-
the error $\|f - p_n\|_\infty$ only decreases as $n$ increases
546-
when the right-hand side (RHS) of (8) is bounded by a constant. So let's check this for our functions.
566+
if the right-hand side (RHS) of (8) goes to zero,
567+
than the the error $\|f - p_n\|_\infty$ neccessirly vanishes
568+
as $n$ increases.
569+
570+
So let's check this for our functions.
547571
- For $f_\text{sin}(x) = \sin(5x)$ we can easily verify
548572
$|f_\text{sin}^{(n+1)}(x)| = 5 |f_\text{sin}^{(n)}(x)|$ as well as $\max_{[-1,1]} |f_\text{sin}(x)| = \max_{x\in[-1,1]} |\sin(5x)| = 1$, such that
549573
```math
@@ -609,12 +633,12 @@ This visual result is also confirmed by a more detailed analysis,
609633
which reveals, that the origin is our choice of a *regular* spacing between the sampling points, an effect known as Runge's phaenomenon.
610634
611635
!!! info "Observation: Runge's phaenomenon"
612-
Polynomial interpolation employing *equally spaced* nodal points
613-
to construct the interpolant $p_n$ *may* lead to a non-convergence
636+
Polynomial interpolation employing **equally spaced nodal points**
637+
to construct the interpolant $p_n$ **may lead to a non-convergence**
614638
as $n \to \infty$. Moreover while for small $n$ the error in the
615639
infinity norm $\|\,\cdot\,\|_\infty$ still
616640
decreases, for large $n$ this behaviour can change, such that
617-
for large $n$ the error *keeps increasing* as $n$ increases.
641+
**for large $n$ the error can keep increasing** as $n$ increases.
618642
"""
619643

620644
# ╔═╡ 25b82572-b27d-4f0b-9be9-323cd4e3ce7a
@@ -704,10 +728,9 @@ is one of the **desired properties**.
704728
* If the error scales as $C K^{-n}$ where $n$ is the iteration number, we say the scheme has **linear convergence**. (Compare to the last chapter.)
705729
- **Approximation schemes:** Exponential convergence
706730
* If the error scales as $C K^{-n}$ where $n$ is some accuracy parameter (with larger $n$ giving more accurate results), then we say the scheme has **exponential convergence**.
707-
* For approximation schemes it is often more convenient to instead formulate the method using an approximation parameter $h = O(1/n)$, i.e. which scales inversely to $n$. In this case *smaller* $h$ give more accurate results. In this case exponential convergence is characterised by an error scaling as $C K^h$.
708731
"""
709732

710-
# ╔═╡ 1d61d925-1ceb-439b-aff6-c5e8483fdc31
733+
# ╔═╡ a15750a3-3507-4ee1-8b9a-b7d6a3dcea46
711734
md"""
712735
### Stability of polynomial interpolation
713736
@@ -730,7 +753,10 @@ Instead of producing an interpolating polynomial $p_n$
730753
using the exact data $(x_i, y_i)$,
731754
our procedure only has access to the noisy data $(x_i, \tilde{y}_i)$,
732755
thus producing the polynomial $\tilde{p}_n$.
756+
"""
733757

758+
# ╔═╡ 7f855423-72ac-4e6f-92bc-73c12e5007eb
759+
md"""
734760
In **stabilty analysis** we now ask the question:
735761
How different are $p_n$ and $\tilde{p}_n$ given a measurement noise
736762
of order $\varepsilon$.
@@ -833,16 +859,16 @@ let
833859
for (i, values) in enumerate((values_equispaced, values_chebyshev))
834860
noise = [10^η_log_poly * (-1 + 2rand()) for _ in values]
835861

836-
fsin_accurate = fsin.(values) # = [fsin(x) for x in values]
862+
# fsin_accurate = fsin.(values) # = [fsin(x) for x in values]
837863
fsin_noise = fsin.(values) + noise
838864

839-
poly_accurate = Polynomials.fit(values, fsin_accurate)
865+
# poly_accurate = Polynomials.fit(values, fsin_accurate)
840866
poly_noise = Polynomials.fit(values, fsin_noise)
841867

842868
plot!(p, fine, fsin.(fine);
843869
label=L"function $f$", subplot=i, lw=2, ls=:dash,
844870
ylim=(-2.75, 2), legend=:bottomright)
845-
plot!(p, fine, poly_accurate.(fine); label=L"accurate $p_n$", subplot=i, lw=2)
871+
# plot!(p, fine, poly_accurate.(fine); label=L"accurate $p_n$", subplot=i, lw=2)
846872
plot!(p, fine, poly_noise.(fine); label=L"noisy $\tilde{p}_n$", subplot=i, lw=2)
847873
scatter!(p, values, fsin_noise; subplot=i, label="noisy data")
848874

@@ -3242,6 +3268,7 @@ version = "1.4.1+2"
32423268
# ╠═f40c7c2e-339c-4b6e-91d3-ef5d031091f3
32433269
# ╟─944fa679-77d2-4fe5-9a79-ef63248105c7
32443270
# ╟─055cb883-a140-4078-bedb-666f7e6259d0
3271+
# ╟─669f818c-8f7c-4e6d-9d89-ea979e69ce66
32453272
# ╟─5f1abde6-f4fc-4c5e-9a19-abf28ca3584d
32463273
# ╠═b1773d1c-4d3c-4f4b-805d-f188623c9571
32473274
# ╟─e567287b-9244-4b55-9f5b-2e3bf583e46a
@@ -3258,7 +3285,8 @@ version = "1.4.1+2"
32583285
# ╟─479a234e-1ce6-456d-903a-048bbb3de65a
32593286
# ╟─d4cf71ef-576d-4900-9608-475dbd4d933a
32603287
# ╟─56685887-7866-446c-acdb-2c20bd11d4cd
3261-
# ╟─1d61d925-1ceb-439b-aff6-c5e8483fdc31
3288+
# ╟─a15750a3-3507-4ee1-8b9a-b7d6a3dcea46
3289+
# ╟─7f855423-72ac-4e6f-92bc-73c12e5007eb
32623290
# ╟─eaaf2227-1a19-4fbc-a5b4-45503e832280
32633291
# ╟─d9e318e7-5ffc-4433-9b0c-f393948c10ef
32643292
# ╟─9c8b168d-494b-40ae-bc04-5dff7b535459

0 commit comments

Comments
 (0)