{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.4 Interpolation par intervalles\n",
"\n",
"### Interpolation linéaire par morceaux\n",
"\n",
"Soit $f: \\mathbf [a,b] \\rightarrow R$ continue et $a=x_0<\\ldots\n",
"\n",
"## 2.4.2 Convergence\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# importing libraries used in this book\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from InterpolationLib import PiecewiseLinearInterpolation as PiH1\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"La fonction `PiH1` implémente l'interpolation linéaire par morceaux pour des points équidistribués\n",
"\n",
"```python\n",
"def PiecewiseLinearInterpolation(a,b,N,f,z):\n",
" # the input variables are:\n",
" # a,b : x[0] = a, x[n] = b\n",
" # f : the corresponding data at the points x\n",
" # z : where to evaluate the function\n",
"```\n",
" \n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice\n",
"\n",
"Soient $x_k, k=0,...,4$ des points équidistribués sur l'intervalle $[1,5]$ et \n",
"$y_k = (3.38, 3.86, 3.85, 3.59, 3.49)$\n",
"les valeurs d'une fonction en ces points. \n",
"\n",
"* Dessinez le graphe de l'interpolateur par morceaux de cette fonction\n",
"* Calculez numériquement (sur papier) la valeur de $\\Pi^H_1(4.5)$ et vérifiez le résultat sur le graphique\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# intervalle d'interpolation\n",
"a = 1; b = 5\n",
"\n",
"# (Complete the code below)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice\n",
"\n",
"Dessinez le graphe de la fonction de Runge et l'interpolateur linéaire par morceaux \n",
"sur l'intervalle $[-5,5]$ pour $N=3,5,10$\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# interval and function\n",
"a = -5; b = 5\n",
"f = lambda x : 1/(1+x**2)\n",
"\n",
"# (Complete the code below)\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Erreur d'interpolation linéaire par morceaux \n",
"\n",
"#### Théorème \n",
"\n",
"Soient $f\\in C^{2}([a,b])$, $H = \\frac{b-a}{N}$, $x_i = a + iH$ pour $i=0,...,N$.\n",
" \n",
"Soit $E^H_1f(t) = f(t) - \\Pi_1^{H} f(t)$, alors\n",
"$$\\max_{x\\in I}\\mid E^H_1f(t) \\mid\\leq \\dfrac{H^2}{4}\\max_{x \\in I} | f''(t)|.$$\n",
"\n",
"**Preuve**\n",
"D'après la formule, sur chaque intervalle $I_i=[x_i,x_{i+1}]$, on a\n",
" \n",
"$$\\max_{x\\in[x_i,x_{i+1}]}\\mid E^H_1f(t)\\mid \\leq\n",
" \\dfrac{H^2}{2(1+1)}\\max_{x\\in I_i}\\mid f''(t)\\mid.$$\n",
"\n",
"**Remarque**\n",
"On peut aussi montrer que, si l'on utilise un polynôme\n",
"de degré $n$ ($\\geq 1$) et si l'on dénote $E^H_nf(t) = f(t) - \\Pi_n^{H} f(t)$,\n",
" dans chaque sous-intervalle $I_i$, on\n",
"trouve\n",
"\n",
"$$\\max_{x\\in I}\\mid E^H_nf(t) \\mid \\leq \\dfrac{H^{n+1}}{2(n+1)} \\max_{x \\in I} |f^{(n+1)} (t)| \\, .$$\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Interpolation quadratique par morceaux\n",
"\n",
"Soit $f: \\mathbf [a,b] \\rightarrow R$ continue et $a=x_0<\\ldots