Skip to content
Snippets Groups Projects
Commit a988f1d8 authored by Olivier Cots's avatar Olivier Cots
Browse files

foo

parent 59d0506e
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
<center>
<h1> TP-Projet d'optimisation numérique </h1>
<h1> Algorithme de Newton </h1>
</center>
%% Cell type:markdown id: tags:
## Implémentation
1. Coder l’algorithme de Newton local en respectant la spécification ci-dessous (fichier `Algorithme_De_Newton.jl`)
%% Cell type:code id: tags:
``` julia
using LinearAlgebra
using Documenter
using Markdown
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:
2. Vérifier que les tests ci-dessous passent.
%% Cell type:code id: tags:
``` julia
using Test
# Tolérance pour les tests d'égalité
tol_erreur = sqrt(eps())
## ajouter les fonctions de test
include("../test/fonctions_de_tests.jl")
include("../test/tester_algo_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
# Tester l'algorithme de Newton
tester_algo_newton(affiche,Algorithme_De_Newton)
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:
``` julia
#using Pkg; Pkg.add("LinearAlgebra"); Pkg.add("Markdown")
# using Documenter
using LinearAlgebra
using Markdown # Pour que les docstrings en début des fonctions ne posent
# pas de soucis. Ces docstrings sont utiles pour générer
# la documentation sous GitHub
include("Algorithme_De_Newton.jl")
# 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)
println("-------------------------------------------------------------------------")
printstyled("Résultats de : ",algo, " appliqué à ",nom_fct, " au point initial ", point_init, ":\n",bold=true,color=:blue)
println(" * xsol = ",xmin)
println(" * f(xsol) = ",fxmin)
println(" * nb_iters = ",nbiters)
println(" * flag = ",flag)
println(" * sol_exacte : ", sol_exacte)
end
# Fonction f0
# -----------
f0(x) = sin(x)
# la gradient de la fonction f0
grad_f0(x) = cos(x)
# la hessienne de la fonction f0
hess_f0(x) = -sin(x)
sol_exacte = -pi/2
options = []
x0 = sol_exacte
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)
x0 = -pi/2+0.5
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)
x0 = pi/2
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)
```
%% 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:
## Interprétation
1. Justifier les résultats obtenus pour l'exemple $f_0$ ci-dessus;
2. Soit
$$ f_{1} : \mathbb{R}^3 \rightarrow \mathbb{R}$$ $$ (x_1,x_2, x_3) \mapsto 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}$;
3. Soit
$$ f_{2} : \mathbb{R}^2 \rightarrow \mathbb{R}$$ $$ (x_1,x_2) \mapsto 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.
%% Cell type:code id: tags:
``` julia
```
**Remarque.** Vous pouvez mettre `affiche=true` dans les tests de l'algorithme de Newton pour
vous aider.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment