Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
controle4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
maths
controle4
Commits
4fdfb248
Commit
4fdfb248
authored
10 months ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
not liking that one bit
parent
1e071230
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ISC_421_Controle_4_Saroukhanian_Iliya.py
+71
-3
71 additions, 3 deletions
ISC_421_Controle_4_Saroukhanian_Iliya.py
figs/newton_interpolate.png
+0
-0
0 additions, 0 deletions
figs/newton_interpolate.png
report.qmd
+17
-2
17 additions, 2 deletions
report.qmd
with
88 additions
and
5 deletions
ISC_421_Controle_4_Saroukhanian_Iliya.py
+
71
−
3
View file @
4fdfb248
import
numpy
as
np
import
math
from
matplotlib
import
pyplot
as
plt
from
scipy.interpolate
import
lagrange
from
scipy.interpolate
import
lagrange
,
barycentric_interpolate
from
numpy.polynomial.polynomial
import
Polynomial
...
...
@@ -204,7 +204,7 @@ def ex2_taylor_poly():
plt
.
show
()
def
ex3_interpolation_poly
():
def
ex3_
lagrange_
interpolation_poly
():
nb_points
=
np
.
linspace
(
3
,
19
,
6
,
dtype
=
np
.
uint64
)
fig
,
axes
=
plt
.
subplots
(
2
,
3
,
figsize
=
(
20
,
12
))
...
...
@@ -244,7 +244,75 @@ def ex3_interpolation_poly():
plt
.
show
()
ex3_interpolation_poly
()
def
ex3_newton_interpolation_poly
():
# merce l'ami
def
divided_differences
(
x
,
y
):
n
=
len
(
y
)
coef
=
np
.
zeros
([
n
,
n
])
coef
[:,
0
]
=
y
for
j
in
range
(
1
,
n
):
for
i
in
range
(
n
-
j
):
coef
[
i
,
j
]
=
(
coef
[
i
+
1
,
j
-
1
]
-
coef
[
i
,
j
-
1
])
/
\
(
x
[
i
+
j
]
-
x
[
i
])
return
coef
[
0
,
:]
def
newton_polynomial
(
x
,
x_points
,
coef
):
n
=
len
(
coef
)
p
=
coef
[
n
-
1
]
for
k
in
range
(
1
,
n
):
p
=
coef
[
n
-
k
-
1
]
+
(
x
-
x_points
[
n
-
k
-
1
])
*
p
return
p
nb_points
=
np
.
linspace
(
3
,
19
,
6
,
dtype
=
np
.
uint64
)
fig
,
axes
=
plt
.
subplots
(
2
,
3
,
figsize
=
(
20
,
12
))
t
=
np
.
linspace
(
SD
.
a
,
SD
.
b
,
Nmbre_pts
)
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
])
y_points_uni
=
SD
.
f
(
interpolate_pts
)
coef_uni
=
divided_differences
(
interpolate_pts
,
y_points_uni
)
y_plot_uni
=
newton_polynomial
(
t
,
interpolate_pts
,
coef_uni
)
y_points_cheb
=
SD
.
f
(
chebyshev_points_mapped
)
coef_cheb
=
divided_differences
(
chebyshev_points_mapped
,
y_points_cheb
)
y_plot_cheb
=
newton_polynomial
(
t
,
chebyshev_points_mapped
,
coef_cheb
)
ax
.
plot
(
t
,
SD
.
f
(
t
),
color
=
'
black
'
,
label
=
'
f
'
)
ax
.
plot
(
t
,
y_plot_uni
,
color
=
'
red
'
,
label
=
'
$N_{f}$, intervalle équidistants
'
)
ax
.
plot
(
t
,
y_plot_cheb
,
color
=
'
blue
'
,
label
=
'
$N_{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 Newton de $f$ avec 2 subdivisions différentes d
\'
intervalle: Équidistantes (rouge) / Points de Chebyshev (bleu)
'
)
fig
.
tight_layout
()
plt
.
show
()
ex3_newton_interpolation_poly
()
# Graphique des polynômes de Taylor
# fig, axes = plt.subplots(1, 3)
...
...
This diff is collapsed.
Click to expand it.
figs/newton_interpolate.png
0 → 100644
+
0
−
0
View file @
4fdfb248
293 KiB
This diff is collapsed.
Click to expand it.
report.qmd
+
17
−
2
View file @
4fdfb248
...
...
@@ -37,11 +37,26 @@ $$
# Polynômes d'interpolation
Dans cette partie, nous allons présenter les graphiques de divers polynômes
d'interpolation. Il était aussi demandé d'effectuer ces interpolations en
subdivisant l'intervalle $I = [a, b]$ (où $a = 1$ et $b = 4$ dans mon cas) de
deux manières différentes. Les points rouges réprensentent donc le découpage
uniforme / équidistant. Quant au bleus, ceux-ci sont les points de Chebyshev
(comme vous avez pu le deviner, ceux-ci ne sont pas équidistants).
## Lagrange
![Polynôme de Lagrange avec subdivision uniforme de l'intervalle $I = [a, b]$](./figs/lagrange_interpolate.png)
Le graphique ci-dessous met en avant l'interpolation par le polynôme de
Lagrange.

## Newton
Le graphique ci-dessous met en avant l'interpolation par le polynôme de
Newton.
## Hermite

# Exercice 3
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment