Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Optimisation numérique - Projet
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
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
toc
Etudiants N7
Optimisation numérique - Projet
Commits
a988f1d8
Commit
a988f1d8
authored
2 years ago
by
Olivier Cots
Browse files
Options
Downloads
Patches
Plain Diff
foo
parent
59d0506e
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
src/algo_newton.ipynb
+16
-82
16 additions, 82 deletions
src/algo_newton.ipynb
with
16 additions
and
82 deletions
src/algo_newton.ipynb
+
16
−
82
View file @
a988f1d8
...
@@ -21,36 +21,15 @@
...
@@ -21,36 +21,15 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
1
,
"execution_count":
null
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [],
{
"ename": "LoadError",
"evalue": "LoadError: syntax: invalid escape sequence\nin expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
"output_type": "error",
"traceback": [
"LoadError: syntax: invalid escape sequence\nin expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
"",
"Stacktrace:",
" [1] top-level scope",
" @ ~/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
" [2] include(fname::String)",
" @ Base.MainInclude ./client.jl:444",
" [3] top-level scope",
" @ In[1]:4",
" [4] eval",
" @ ./boot.jl:360 [inlined]",
" [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)",
" @ Base ./loading.jl:1116"
]
}
],
"source": [
"source": [
"using LinearAlgebra\n",
"using LinearAlgebra\n",
"using Documenter\n",
"using Documenter\n",
"using Markdown \n",
"using Markdown \n",
"include(\"Algorithme_De_Newton.jl\")\n",
"include(\"Algorithme_De_Newton.jl\")\n",
"
#
@doc Algorithme_De_Newton"
"@doc Algorithme_De_Newton"
]
]
},
},
{
{
...
@@ -62,30 +41,9 @@
...
@@ -62,30 +41,9 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
2
,
"execution_count":
null
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [],
{
"ename": "LoadError",
"evalue": "LoadError: syntax: invalid escape sequence\nin expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
"output_type": "error",
"traceback": [
"LoadError: syntax: invalid escape sequence\nin expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
"",
"Stacktrace:",
" [1] top-level scope",
" @ ~/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
" [2] include(fname::String)",
" @ Base.MainInclude ./client.jl:444",
" [3] top-level scope",
" @ In[2]:9",
" [4] eval",
" @ ./boot.jl:360 [inlined]",
" [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)",
" @ Base ./loading.jl:1116"
]
}
],
"source": [
"source": [
"using Test\n",
"using Test\n",
"\n",
"\n",
...
@@ -97,7 +55,9 @@
...
@@ -97,7 +55,9 @@
"include(\"../test/tester_algo_newton.jl\")\n",
"include(\"../test/tester_algo_newton.jl\")\n",
"include(\"../src/Algorithme_De_Newton.jl\")\n",
"include(\"../src/Algorithme_De_Newton.jl\")\n",
"\n",
"\n",
"affiche = false\n",
"affiche = false # Mettre affiche = true pour afficher les résultats \n",
"\t\t\t\t# des appels à l'algorithme de Newton. Cela peut vous\n",
"\t\t\t\t# servir pour les réponses aux questions en fin de notebook.\n",
"\n",
"\n",
"@testset \"Test algo newton\" begin\n",
"@testset \"Test algo newton\" begin\n",
"\t# Tester l'algorithme de Newton\n",
"\t# Tester l'algorithme de Newton\n",
...
@@ -107,30 +67,9 @@
...
@@ -107,30 +67,9 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
3
,
"execution_count":
null
,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [],
{
"ename": "LoadError",
"evalue": "LoadError: syntax: invalid escape sequence\nin expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
"output_type": "error",
"traceback": [
"LoadError: syntax: invalid escape sequence\nin expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
"",
"Stacktrace:",
" [1] top-level scope",
" @ ~/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42",
" [2] include(fname::String)",
" @ Base.MainInclude ./client.jl:444",
" [3] top-level scope",
" @ In[3]:7",
" [4] eval",
" @ ./boot.jl:360 [inlined]",
" [5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)",
" @ Base ./loading.jl:1116"
]
}
],
"source": [
"source": [
"#using Pkg; Pkg.add(\"LinearAlgebra\"); Pkg.add(\"Markdown\")\n",
"#using Pkg; Pkg.add(\"LinearAlgebra\"); Pkg.add(\"Markdown\")\n",
"# using Documenter\n",
"# using Documenter\n",
...
@@ -189,28 +128,23 @@
...
@@ -189,28 +128,23 @@
"$$ f_{2} : \\mathbb{R}^2 \\rightarrow \\mathbb{R}$$ $$ (x_1,x_2) \\mapsto 100(x_2-x_1^2)^2 + (1-x_1)^2 $$ \n",
"$$ f_{2} : \\mathbb{R}^2 \\rightarrow \\mathbb{R}$$ $$ (x_1,x_2) \\mapsto 100(x_2-x_1^2)^2 + (1-x_1)^2 $$ \n",
"\n",
"\n",
"Justifier que l’algorithme puisse ne pas converger pour $f_{2}$ avec certains points initiaux.\n",
"Justifier que l’algorithme puisse ne pas converger pour $f_{2}$ avec certains points initiaux.\n",
"\n"
"\n",
"**Remarque.** Vous pouvez mettre `affiche=true` dans les tests de l'algorithme de Newton pour\n",
"vous aider.\n"
]
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
}
],
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "Julia 1.
6.6
",
"display_name": "Julia 1.
8.2
",
"language": "julia",
"language": "julia",
"name": "julia-1.
6
"
"name": "julia-1.
8
"
},
},
"language_info": {
"language_info": {
"file_extension": ".jl",
"file_extension": ".jl",
"mimetype": "application/julia",
"mimetype": "application/julia",
"name": "julia",
"name": "julia",
"version": "1.
6.6
"
"version": "1.
8.2
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
<center>
<center>
<h1>
TP-Projet d'optimisation numérique
</h1>
<h1>
TP-Projet d'optimisation numérique
</h1>
<h1>
Algorithme de Newton
</h1>
<h1>
Algorithme de Newton
</h1>
</center>
</center>
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Implémentation
## Implémentation
1.
Coder l’algorithme de Newton local en respectant la spécification ci-dessous (fichier
`Algorithme_De_Newton.jl`
)
1.
Coder l’algorithme de Newton local en respectant la spécification ci-dessous (fichier
`Algorithme_De_Newton.jl`
)
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
julia
```
julia
using
LinearAlgebra
using
LinearAlgebra
using
Documenter
using
Documenter
using
Markdown
using
Markdown
include
(
"Algorithme_De_Newton.jl"
)
include
(
"Algorithme_De_Newton.jl"
)
#
@doc Algorithme_De_Newton
@doc
Algorithme_De_Newton
```
```
%% Output
LoadError: syntax: invalid escape sequence
in expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42
Stacktrace:
[1] top-level scope
@ ~/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42
[2] include(fname::String)
@ Base.MainInclude ./client.jl:444
[3] top-level scope
@ In[1]:4
[4] eval
@ ./boot.jl:360 [inlined]
[5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1116
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
2.
Vérifier que les tests ci-dessous passent.
2.
Vérifier que les tests ci-dessous passent.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
julia
```
julia
using
Test
using
Test
# Tolérance pour les tests d'égalité
# Tolérance pour les tests d'égalité
tol_erreur
=
sqrt
(
eps
())
tol_erreur
=
sqrt
(
eps
())
## ajouter les fonctions de test
## ajouter les fonctions de test
include
(
"../test/fonctions_de_tests.jl"
)
include
(
"../test/fonctions_de_tests.jl"
)
include
(
"../test/tester_algo_newton.jl"
)
include
(
"../test/tester_algo_newton.jl"
)
include
(
"../src/Algorithme_De_Newton.jl"
)
include
(
"../src/Algorithme_De_Newton.jl"
)
affiche
=
false
affiche
=
false
# Mettre affiche = true pour afficher les résultats
# des appels à l'algorithme de Newton. Cela peut vous
# servir pour les réponses aux questions en fin de notebook.
@testset
"Test algo newton"
begin
@testset
"Test algo newton"
begin
# Tester l'algorithme de Newton
# Tester l'algorithme de Newton
tester_algo_newton
(
affiche
,
Algorithme_De_Newton
)
tester_algo_newton
(
affiche
,
Algorithme_De_Newton
)
end
;
end
;
```
```
%% Output
LoadError: syntax: invalid escape sequence
in expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42
Stacktrace:
[1] top-level scope
@ ~/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42
[2] include(fname::String)
@ Base.MainInclude ./client.jl:444
[3] top-level scope
@ In[2]:9
[4] eval
@ ./boot.jl:360 [inlined]
[5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1116
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
julia
```
julia
#using Pkg; Pkg.add("LinearAlgebra"); Pkg.add("Markdown")
#using Pkg; Pkg.add("LinearAlgebra"); Pkg.add("Markdown")
# using Documenter
# using Documenter
using
LinearAlgebra
using
LinearAlgebra
using
Markdown
# Pour que les docstrings en début des fonctions ne posent
using
Markdown
# Pour que les docstrings en début des fonctions ne posent
# pas de soucis. Ces docstrings sont utiles pour générer
# pas de soucis. Ces docstrings sont utiles pour générer
# la documentation sous GitHub
# la documentation sous GitHub
include
(
"Algorithme_De_Newton.jl"
)
include
(
"Algorithme_De_Newton.jl"
)
# Affichage les sorties de l'algorithme des Régions de confiance
# Affichage les sorties de l'algorithme des Régions de confiance
function
my_afficher_resultats
(
algo
,
nom_fct
,
point_init
,
xmin
,
fxmin
,
flag
,
sol_exacte
,
nbiters
)
function
my_afficher_resultats
(
algo
,
nom_fct
,
point_init
,
xmin
,
fxmin
,
flag
,
sol_exacte
,
nbiters
)
println
(
"-------------------------------------------------------------------------"
)
println
(
"-------------------------------------------------------------------------"
)
printstyled
(
"Résultats de : "
,
algo
,
" appliqué à "
,
nom_fct
,
" au point initial "
,
point_init
,
":
\n
"
,
bold
=
true
,
color
=:
blue
)
printstyled
(
"Résultats de : "
,
algo
,
" appliqué à "
,
nom_fct
,
" au point initial "
,
point_init
,
":
\n
"
,
bold
=
true
,
color
=:
blue
)
println
(
" * xsol = "
,
xmin
)
println
(
" * xsol = "
,
xmin
)
println
(
" * f(xsol) = "
,
fxmin
)
println
(
" * f(xsol) = "
,
fxmin
)
println
(
" * nb_iters = "
,
nbiters
)
println
(
" * nb_iters = "
,
nbiters
)
println
(
" * flag = "
,
flag
)
println
(
" * flag = "
,
flag
)
println
(
" * sol_exacte : "
,
sol_exacte
)
println
(
" * sol_exacte : "
,
sol_exacte
)
end
end
# Fonction f0
# Fonction f0
# -----------
# -----------
f0
(
x
)
=
sin
(
x
)
f0
(
x
)
=
sin
(
x
)
# la gradient de la fonction f0
# la gradient de la fonction f0
grad_f0
(
x
)
=
cos
(
x
)
grad_f0
(
x
)
=
cos
(
x
)
# la hessienne de la fonction f0
# la hessienne de la fonction f0
hess_f0
(
x
)
=
-
sin
(
x
)
hess_f0
(
x
)
=
-
sin
(
x
)
sol_exacte
=
-
pi
/
2
sol_exacte
=
-
pi
/
2
options
=
[]
options
=
[]
x0
=
sol_exacte
x0
=
sol_exacte
xmin
,
f_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
f0
,
grad_f0
,
hess_f0
,
x0
,
options
)
xmin
,
f_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
f0
,
grad_f0
,
hess_f0
,
x0
,
options
)
my_afficher_resultats
(
"Newton"
,
"f0"
,
x0
,
xmin
,
f_min
,
flag
,
sol_exacte
,
nb_iters
)
my_afficher_resultats
(
"Newton"
,
"f0"
,
x0
,
xmin
,
f_min
,
flag
,
sol_exacte
,
nb_iters
)
x0
=
-
pi
/
2
+
0.5
x0
=
-
pi
/
2
+
0.5
xmin
,
f_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
f0
,
grad_f0
,
hess_f0
,
x0
,
options
)
xmin
,
f_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
f0
,
grad_f0
,
hess_f0
,
x0
,
options
)
my_afficher_resultats
(
"Newton"
,
"f0"
,
x0
,
xmin
,
f_min
,
flag
,
sol_exacte
,
nb_iters
)
my_afficher_resultats
(
"Newton"
,
"f0"
,
x0
,
xmin
,
f_min
,
flag
,
sol_exacte
,
nb_iters
)
x0
=
pi
/
2
x0
=
pi
/
2
xmin
,
f_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
f0
,
grad_f0
,
hess_f0
,
x0
,
options
)
xmin
,
f_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
f0
,
grad_f0
,
hess_f0
,
x0
,
options
)
my_afficher_resultats
(
"Newton"
,
"f0"
,
x0
,
xmin
,
f_min
,
flag
,
sol_exacte
,
nb_iters
)
my_afficher_resultats
(
"Newton"
,
"f0"
,
x0
,
xmin
,
f_min
,
flag
,
sol_exacte
,
nb_iters
)
```
```
%% Output
LoadError: syntax: invalid escape sequence
in expression starting at /Users/gergaud/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42
Stacktrace:
[1] top-level scope
@ ~/git-ENS/optimisation-numerique/projet-optinum/src/Algorithme_De_Newton.jl:42
[2] include(fname::String)
@ Base.MainInclude ./client.jl:444
[3] top-level scope
@ In[3]:7
[4] eval
@ ./boot.jl:360 [inlined]
[5] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1116
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Interprétation
## Interprétation
1.
Justifier les résultats obtenus pour l'exemple $f_0$ ci-dessus;
1.
Justifier les résultats obtenus pour l'exemple $f_0$ ci-dessus;
2.
Soit
2.
Soit
$$ f_{1} :
\m
athbb{R}^3
\r
ightarrow
\m
athbb{R}$$ $$ (x_1,x_2, x_3)
\m
apsto 2 (x_1 +x_2 + x_3 -3)^2 + (x_1-x_2)^2 + (x_2 - x_3)^2$$
$$ f_{1} :
\m
athbb{R}^3
\r
ightarrow
\m
athbb{R}$$ $$ (x_1,x_2, x_3)
\m
apsto 2 (x_1 +x_2 + x_3 -3)^2 + (x_1-x_2)^2 + (x_2 - x_3)^2$$
Justifier que l’algorithme implémenté converge en une itération pour $f_{1}$;
Justifier que l’algorithme implémenté converge en une itération pour $f_{1}$;
3.
Soit
3.
Soit
$$ f_{2} :
\m
athbb{R}^2
\r
ightarrow
\m
athbb{R}$$ $$ (x_1,x_2)
\m
apsto 100(x_2-x_1^2)^2 + (1-x_1)^2 $$
$$ f_{2} :
\m
athbb{R}^2
\r
ightarrow
\m
athbb{R}$$ $$ (x_1,x_2)
\m
apsto 100(x_2-x_1^2)^2 + (1-x_1)^2 $$
Justifier que l’algorithme puisse ne pas converger pour $f_{2}$ avec certains points initiaux.
Justifier que l’algorithme puisse ne pas converger pour $f_{2}$ avec certains points initiaux.
**Remarque.**
Vous pouvez mettre
`affiche=true`
dans les tests de l'algorithme de Newton pour
%% Cell type:code id: tags:
vous aider.
```
julia
```
...
...
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