Skip to content
Snippets Groups Projects
Commit 5a1a725b authored by iliya.saroukha's avatar iliya.saroukha :first_quarter_moon:
Browse files

feat: added lagrange interpolation with uniform interval subdivision as well...

feat: added lagrange interpolation with uniform interval subdivision as well as using Chebyshev's points
parent 974722c6
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import numpy as np ...@@ -2,6 +2,7 @@ import numpy as np
import math import math
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from scipy.interpolate import lagrange from scipy.interpolate import lagrange
from numpy.polynomial.polynomial import Polynomial
############################################################################# #############################################################################
...@@ -152,7 +153,7 @@ print(f"valeur de la fonction en a et b: {SD.f(SD.a), SD.f(SD.b)}") ...@@ -152,7 +153,7 @@ print(f"valeur de la fonction en a et b: {SD.f(SD.a), SD.f(SD.b)}")
#### Exercices ##### #### Exercices #####
########################################################################### ###########################################################################
def ex2(): def ex2_taylor_poly():
t = np.linspace(SD.a, SD.b, Nmbre_pts) t = np.linspace(SD.a, SD.b, Nmbre_pts)
y0 = compute_taylor_series( y0 = compute_taylor_series(
t, SD.Taylor_points[0], SD.Taylor_derivatives_values[SD.Taylor_points[0]]) t, SD.Taylor_points[0], SD.Taylor_derivatives_values[SD.Taylor_points[0]])
...@@ -203,7 +204,47 @@ def ex2(): ...@@ -203,7 +204,47 @@ def ex2():
plt.show() plt.show()
ex2() def ex3_interpolation_poly():
nb_points = np.linspace(3, 19, 6, dtype=np.uint64)
fig, axes = plt.subplots(2, 3, figsize=(20, 12))
for i, ax in enumerate(axes.flat):
chebyshev_points = np.cos(
(2 * np.arange(nb_points[i]) + 1) / (2 * nb_points[i]) * np.pi)
chebyshev_points_mapped = 0.5 * \
(SD.b - SD.a) * (chebyshev_points + 1) + SD.a
interpolate_pts = np.linspace(SD.a, SD.b, nb_points[i])
l_poly_uniform = lagrange(interpolate_pts, SD.f(interpolate_pts))
l_poly_chebyshev_pts = lagrange(
chebyshev_points_mapped, SD.f(chebyshev_points_mapped))
t = np.linspace(SD.a, SD.b, Nmbre_pts)
ax.plot(t, SD.f(t), color='black', label='f')
ax.plot(t, l_poly_uniform(t), color='red',
label='$L_{f}$, intervalle équidistants')
ax.plot(t, l_poly_chebyshev_pts(t), color='blue',
label='$L_{f}$, points de Chebyshev')
ax.plot(interpolate_pts, SD.f(interpolate_pts), 'o', color='red',
label='Points équidistants')
ax.plot(chebyshev_points_mapped[::-1],
SD.f(chebyshev_points_mapped[::-1]), 'o', color='blue',
label='Points de Chebyshev')
ax.set_title(f'n = {nb_points[i]}')
ax.set_ylim([-1.2, 1.2])
ax.legend()
fig.suptitle(f'Polynôme d\'interpolation de Lagrange de $f$ avec 2 subdivisions différentes d\'intervalle: Équidistantes (rouge) / Points de Chebyshev (bleu)')
fig.tight_layout()
plt.show()
ex3_interpolation_poly()
# Graphique des polynômes de Taylor # Graphique des polynômes de Taylor
# fig, axes = plt.subplots(1, 3) # fig, axes = plt.subplots(1, 3)
......
figs/interpolate_lagrange_uniform.png

95.6 KiB

figs/lagrange_interpolate.png

293 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment