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
374d8cde
Commit
374d8cde
authored
10 months ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
feat: wrote taylor_errmax and updated chebyshev_points function
parent
7760c9a9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ISC_421_Controle_4_Saroukhanian_Iliya.py
+34
-14
34 additions, 14 deletions
ISC_421_Controle_4_Saroukhanian_Iliya.py
with
34 additions
and
14 deletions
ISC_421_Controle_4_Saroukhanian_Iliya.py
+
34
−
14
View file @
374d8cde
...
...
@@ -155,17 +155,30 @@ print(f"valeur de la fonction en a et b: {SD.f(SD.a), SD.f(SD.b)}")
#### Exercices #####
###########################################################################
def
taylor_err_max
(
plot_range
,
eval_pt
):
return
(
SD
.
Maximal_derivatives_values
[
len
(
SD
.
Maximal_derivatives_values
)
-
1
]
/
math
.
factorial
(
len
(
SD
.
Maximal_derivatives_values
)
+
1
))
*
\
(
plot_range
-
eval_pt
)
**
(
len
(
SD
.
Maximal_derivatives_values
)
+
1
)
def
ex2_taylor_poly
():
t
=
np
.
linspace
(
SD
.
a
,
SD
.
b
,
Nmbre_pts
)
y0
=
compute_taylor_series
(
t
,
SD
.
Taylor_points
[
0
],
SD
.
Taylor_derivatives_values
[
SD
.
Taylor_points
[
0
]])
err_y0
=
taylor_err_max
(
t
,
SD
.
Taylor_points
[
0
])
y1
=
compute_taylor_series
(
t
,
SD
.
Taylor_points
[
1
],
SD
.
Taylor_derivatives_values
[
SD
.
Taylor_points
[
1
]])
err_y1
=
taylor_err_max
(
t
,
SD
.
Taylor_points
[
1
])
y2
=
compute_taylor_series
(
t
,
SD
.
Taylor_points
[
2
],
SD
.
Taylor_derivatives_values
[
SD
.
Taylor_points
[
2
]])
err_y2
=
taylor_err_max
(
t
,
SD
.
Taylor_points
[
2
])
fig
,
axs
=
plt
.
subplots
(
2
,
2
,
figsize
=
(
18
,
12
))
axs
[
0
,
0
].
plot
(
t
,
SD
.
f
(
t
),
color
=
'
black
'
)
...
...
@@ -174,6 +187,8 @@ def ex2_taylor_poly():
axs
[
0
,
1
].
plot
(
t
,
SD
.
f
(
t
),
color
=
'
black
'
,
label
=
'
$f$
'
)
axs
[
0
,
1
].
plot
(
t
,
y0
,
color
=
'
orange
'
,
label
=
'
$T_{f}$
'
)
axs
[
0
,
1
].
plot
(
t
,
err_y0
,
'
--
'
,
color
=
'
orange
'
,
label
=
'
Erreur maximal de $T_{f}$
'
)
axs
[
0
,
1
].
plot
(
SD
.
Taylor_points
[
0
],
SD
.
f
(
SD
.
Taylor_points
[
0
]),
"
-o
"
,
color
=
'
red
'
,
label
=
f
'
a =
{
SD
.
Taylor_points
[
0
]
}
'
)
axs
[
0
,
1
].
set_title
(
...
...
@@ -184,6 +199,8 @@ def ex2_taylor_poly():
axs
[
1
,
0
].
plot
(
t
,
SD
.
f
(
t
),
color
=
'
black
'
,
label
=
'
$f$
'
)
axs
[
1
,
0
].
plot
(
t
,
y1
,
color
=
'
blue
'
,
label
=
'
$T_{f}$
'
)
axs
[
1
,
0
].
plot
(
t
,
err_y1
,
'
--
'
,
color
=
'
blue
'
,
label
=
'
ErrMax de $T_{f}$
'
)
axs
[
1
,
0
].
plot
(
SD
.
Taylor_points
[
1
],
SD
.
f
(
SD
.
Taylor_points
[
1
]),
"
-o
"
,
color
=
'
red
'
,
label
=
f
'
a =
{
SD
.
Taylor_points
[
1
]
}
'
)
axs
[
1
,
0
].
set_title
(
...
...
@@ -194,6 +211,8 @@ def ex2_taylor_poly():
axs
[
1
,
1
].
plot
(
t
,
SD
.
f
(
t
),
color
=
'
black
'
,
label
=
'
$f$
'
)
axs
[
1
,
1
].
plot
(
t
,
y2
,
color
=
'
violet
'
,
label
=
'
$T_{f}$
'
)
axs
[
1
,
1
].
plot
(
t
,
err_y2
,
'
--
'
,
color
=
'
violet
'
,
label
=
'
ErrMax de $T_{f}$
'
)
axs
[
1
,
1
].
plot
(
SD
.
Taylor_points
[
2
],
SD
.
f
(
SD
.
Taylor_points
[
2
]),
"
-o
"
,
color
=
'
red
'
,
label
=
f
'
a =
{
SD
.
Taylor_points
[
2
]
}
'
)
axs
[
1
,
1
].
set_title
(
...
...
@@ -223,6 +242,11 @@ def polerr(nb_points, interpolation_pts, plot_range):
return
errs_range
def
chebyshev_pts
(
start
,
stop
,
nb_points
):
return
(((
start
+
stop
)
/
2
)
+
((
stop
-
start
)
/
2
)
*
np
.
cos
(((
2
*
np
.
arange
(
nb_points
)
+
1
)
*
np
.
pi
)
/
(
2
*
(
nb_points
))))
def
ex3_lagrange_interpolation_poly
():
nb_points
=
np
.
linspace
(
1
,
12
,
6
,
dtype
=
np
.
uint8
)
fig
,
axes
=
plt
.
subplots
(
2
,
3
,
figsize
=
(
20
,
12
))
...
...
@@ -230,20 +254,16 @@ def ex3_lagrange_interpolation_poly():
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
cheb_pts
=
chebyshev_pts
(
SD
.
a
,
SD
.
b
,
nb_points
[
i
])
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
(
cheb
yshev_points_mapped
,
SD
.
f
(
chebyshev_points_mapped
))
cheb
_pts
,
SD
.
f
(
cheb_pts
))
uniform_err
=
polerr
(
nb_points
[
i
],
interpolate_pts
,
t
)
chebyshev_err
=
polerr
(
nb_points
[
i
],
cheb
yshev_points_mapped
,
t
)
chebyshev_err
=
polerr
(
nb_points
[
i
],
cheb
_pts
,
t
)
ax
.
plot
(
t
,
SD
.
f
(
t
),
color
=
'
black
'
,
label
=
'
f
'
)
ax
.
plot
(
t
,
l_poly_uniform
(
t
),
color
=
'
red
'
,
...
...
@@ -251,17 +271,17 @@ def ex3_lagrange_interpolation_poly():
# ax.plot(t, np.abs(SD.f(t) - l_poly_uniform(t)), '--', color='red',
# label='$L_{f}$, intervalle équidistants, erreur')
ax
.
plot
(
t
,
uniform_err
,
'
--
'
,
color
=
'
red
'
,
label
=
'
$L_{f}$, intervalle équidistants
, erreur
'
)
label
=
'
ErrMax de
$L_{f}$, intervalle équidistants
'
)
ax
.
plot
(
t
,
l_poly_chebyshev_pts
(
t
),
color
=
'
blue
'
,
label
=
'
$L_{f}$, points de Chebyshev
'
)
# ax.plot(t, np.abs(SD.f(t) - l_poly_chebyshev_pts(t)), '--', color='blue',
# label='$L_{f}$, points de Chebyshev, erreur')
ax
.
plot
(
t
,
chebyshev_err
,
'
--
'
,
color
=
'
blue
'
,
label
=
'
$L_{f}$, points de Chebyshev
, erreur
'
)
label
=
'
ErrMax de
$L_{f}$, points de Chebyshev
'
)
ax
.
plot
(
interpolate_pts
,
SD
.
f
(
interpolate_pts
),
'
o
'
,
color
=
'
red
'
,
label
=
'
Points équidistants
'
)
ax
.
plot
(
cheb
yshev_points_mapped
[::
-
1
],
SD
.
f
(
cheb
yshev_points_mapped
[::
-
1
]),
'
o
'
,
color
=
'
blue
'
,
ax
.
plot
(
cheb
_pts
[::
-
1
],
SD
.
f
(
cheb
_pts
[::
-
1
]),
'
o
'
,
color
=
'
blue
'
,
label
=
'
Points de Chebyshev
'
)
ax
.
set_title
(
f
'
n =
{
nb_points
[
i
]
}
'
)
# ax.set_ylim([-1.2, 1.2])
...
...
@@ -274,12 +294,12 @@ def ex3_lagrange_interpolation_poly():
plt
.
show
()
def
caca
():
print
(
len
(
SD
.
Maximal_derivatives_values
))
#
def caca():
#
print(len(SD.Maximal_derivatives_values))
# ex2_taylor_poly()
ex3_lagrange_interpolation_poly
()
# caca()
# def ex3_newton_interpolation_poly():
...
...
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