style: formattage automatique
This commit is contained in:
parent
c071194284
commit
bd31a72072
|
@ -1,38 +0,0 @@
|
||||||
#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)
|
|
|
@ -6,7 +6,7 @@ Cacher les traces d'appels des tests erronés ou échoués, pour les remettre, d
|
||||||
"""
|
"""
|
||||||
function cacher_stacktrace()
|
function cacher_stacktrace()
|
||||||
Test.eval(quote
|
Test.eval(quote
|
||||||
function record(ts::DefaultTestSet, t::Union{Fail, Error})
|
function record(ts::DefaultTestSet, t::Union{Fail,Error})
|
||||||
if myid() == 1
|
if myid() == 1
|
||||||
#printstyled(ts.description, ": ", color=:white) # afficher la description du testset
|
#printstyled(ts.description, ": ", color=:white) # afficher la description du testset
|
||||||
# ne pas afficher pour les tests interrompus
|
# ne pas afficher pour les tests interrompus
|
||||||
|
|
|
@ -8,7 +8,7 @@ Tester l'algorithme de Newton local
|
||||||
* fct 1 : x011,x012
|
* fct 1 : x011,x012
|
||||||
* fct 2 : x021,x022
|
* fct 2 : x021,x022
|
||||||
"""
|
"""
|
||||||
function tester_algo_newton(afficher::Bool,Algorithme_De_Newton::Function)
|
function tester_algo_newton(afficher::Bool, Algorithme_De_Newton::Function)
|
||||||
max_iter = 100
|
max_iter = 100
|
||||||
Tol_abs = sqrt(eps())
|
Tol_abs = sqrt(eps())
|
||||||
Tol_rel = 1e-15
|
Tol_rel = 1e-15
|
||||||
|
@ -16,12 +16,12 @@ function tester_algo_newton(afficher::Bool,Algorithme_De_Newton::Function)
|
||||||
@testset "L'algo de Newton" begin
|
@testset "L'algo de Newton" begin
|
||||||
@testset "Cas test 1 x0 = solution" begin
|
@testset "Cas test 1 x0 = solution" begin
|
||||||
# point de départ x011
|
# point de départ x011
|
||||||
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct1,grad_fct1,hess_fct1,sol_exacte_fct1,options)
|
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, sol_exacte_fct1, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("algorithme de Newton ","fct1","x011",x_min,fx_min,flag,sol_exacte_fct1,nb_iters)
|
afficher_resultats("algorithme de Newton ", "fct1", "x011", x_min, fx_min, flag, sol_exacte_fct1, nb_iters)
|
||||||
end
|
end
|
||||||
@testset "solution" begin
|
@testset "solution" begin
|
||||||
@test isapprox(x_min, sol_exacte_fct1 , atol = tol_erreur)
|
@test isapprox(x_min, sol_exacte_fct1, atol = tol_erreur)
|
||||||
end
|
end
|
||||||
@testset "itération" begin
|
@testset "itération" begin
|
||||||
@test nb_iters == 0
|
@test nb_iters == 0
|
||||||
|
@ -29,21 +29,21 @@ function tester_algo_newton(afficher::Bool,Algorithme_De_Newton::Function)
|
||||||
end
|
end
|
||||||
@testset "Cas test 1 x0 = x011" begin
|
@testset "Cas test 1 x0 = x011" begin
|
||||||
#point de départ x011
|
#point de départ x011
|
||||||
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct1,grad_fct1,hess_fct1,pts1.x011,options)
|
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, pts1.x011, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("algorithme de Newton ","fct1","x011",x_min,fx_min,flag,sol_exacte_fct1,nb_iters)
|
afficher_resultats("algorithme de Newton ", "fct1", "x011", x_min, fx_min, flag, sol_exacte_fct1, nb_iters)
|
||||||
end
|
end
|
||||||
@testset "solution" begin
|
@testset "solution" begin
|
||||||
@test isapprox(x_min, sol_exacte_fct1 , atol = tol_erreur)
|
@test isapprox(x_min, sol_exacte_fct1, atol = tol_erreur)
|
||||||
end
|
end
|
||||||
@testset "itération" begin
|
@testset "itération" begin
|
||||||
@test nb_iters == 1
|
@test nb_iters == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@testset "Cas test 1 x0 = x012" begin
|
@testset "Cas test 1 x0 = x012" begin
|
||||||
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct1,grad_fct1,hess_fct1,pts1.x012,options)
|
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, pts1.x012, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("algorithme de Newton ","fct1","x012",x_min,fx_min,flag,sol_exacte_fct1,nb_iters)
|
afficher_resultats("algorithme de Newton ", "fct1", "x012", x_min, fx_min, flag, sol_exacte_fct1, nb_iters)
|
||||||
end
|
end
|
||||||
@testset "solution" begin
|
@testset "solution" begin
|
||||||
@test x_min ≈ sol_exacte_fct1 atol = tol_erreur
|
@test x_min ≈ sol_exacte_fct1 atol = tol_erreur
|
||||||
|
@ -53,21 +53,21 @@ function tester_algo_newton(afficher::Bool,Algorithme_De_Newton::Function)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@testset "Cas test 2 x0 = solution" begin
|
@testset "Cas test 2 x0 = solution" begin
|
||||||
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct1,grad_fct1,hess_fct1,sol_exacte_fct1,options)
|
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, sol_exacte_fct1, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("algorithme de Newton ","fct1","x011",x_min,fx_min,flag,sol_exacte_fct1,nb_iters)
|
afficher_resultats("algorithme de Newton ", "fct1", "x011", x_min, fx_min, flag, sol_exacte_fct1, nb_iters)
|
||||||
end
|
end
|
||||||
@testset "solution" begin
|
@testset "solution" begin
|
||||||
@test isapprox(x_min, sol_exacte_fct1 , atol = tol_erreur)
|
@test isapprox(x_min, sol_exacte_fct1, atol = tol_erreur)
|
||||||
end
|
end
|
||||||
@testset "itération" begin
|
@testset "itération" begin
|
||||||
@test nb_iters == 0
|
@test nb_iters == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@testset "Cas test 2 x0 = x021" begin
|
@testset "Cas test 2 x0 = x021" begin
|
||||||
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2,grad_fct2,hess_fct2,pts1.x021,options)
|
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, pts1.x021, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("algorithme de Newton ","fct2","x021",x_min,fx_min,flag,sol_exacte_fct2,nb_iters)
|
afficher_resultats("algorithme de Newton ", "fct2", "x021", x_min, fx_min, flag, sol_exacte_fct2, nb_iters)
|
||||||
end
|
end
|
||||||
@testset "solution" begin
|
@testset "solution" begin
|
||||||
@test x_min ≈ sol_exacte_fct2 atol = tol_erreur
|
@test x_min ≈ sol_exacte_fct2 atol = tol_erreur
|
||||||
|
@ -77,9 +77,9 @@ function tester_algo_newton(afficher::Bool,Algorithme_De_Newton::Function)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@testset "Cas test 2 x0 = x022" begin
|
@testset "Cas test 2 x0 = x022" begin
|
||||||
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2,grad_fct2,hess_fct2,pts1.x022,options)
|
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, pts1.x022, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("algorithme de Newton ","fct2","x022",x_min,fx_min,flag,sol_exacte_fct2,nb_iters)
|
afficher_resultats("algorithme de Newton ", "fct2", "x022", x_min, fx_min, flag, sol_exacte_fct2, nb_iters)
|
||||||
end
|
end
|
||||||
@testset "solution" begin
|
@testset "solution" begin
|
||||||
@test x_min ≈ sol_exacte_fct2 atol = tol_erreur
|
@test x_min ≈ sol_exacte_fct2 atol = tol_erreur
|
||||||
|
@ -92,16 +92,16 @@ function tester_algo_newton(afficher::Bool,Algorithme_De_Newton::Function)
|
||||||
@testset "Cas test 2 x0 = x023" begin
|
@testset "Cas test 2 x0 = x023" begin
|
||||||
options[1] = 1
|
options[1] = 1
|
||||||
sol = [-4.99999958629818e9, 8.673617379884035e-19]
|
sol = [-4.99999958629818e9, 8.673617379884035e-19]
|
||||||
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2,grad_fct2,hess_fct2,pts1.x023,options)
|
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, pts1.x023, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("algorithme de Newton ","fct2","x022",x_min,fx_min,flag,sol_exacte_fct2,nb_iters)
|
afficher_resultats("algorithme de Newton ", "fct2", "x022", x_min, fx_min, flag, sol_exacte_fct2, nb_iters)
|
||||||
end
|
end
|
||||||
@testset "solution" begin
|
@testset "solution" begin
|
||||||
@test x_min ≈ sol atol = tol_erreur
|
@test x_min ≈ sol atol = tol_erreur
|
||||||
end
|
end
|
||||||
@testset "exception" begin
|
@testset "exception" begin
|
||||||
options[1] = 100
|
options[1] = 100
|
||||||
@test_throws SingularException x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2,grad_fct2,hess_fct2,pts1.x023,options)
|
@test_throws SingularException x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, pts1.x023, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ Tester l'algorithme du Lagrangien augmenté
|
||||||
* fct1 : x01, x02
|
* fct1 : x01, x02
|
||||||
* fct2 : x03, x04
|
* fct2 : x03, x04
|
||||||
"""
|
"""
|
||||||
function tester_lagrangien_augmente(afficher::Bool,Lagrangien_Augmente::Function)
|
function tester_lagrangien_augmente(afficher::Bool, Lagrangien_Augmente::Function)
|
||||||
|
|
||||||
# initialisation des paramètres
|
# initialisation des paramètres
|
||||||
lambda0 = 2
|
lambda0 = 2
|
||||||
|
@ -34,36 +34,36 @@ function tester_lagrangien_augmente(afficher::Bool,Lagrangien_Augmente::Function
|
||||||
@testset "Lagrangien augmenté " begin
|
@testset "Lagrangien augmenté " begin
|
||||||
@testset "Avec $algo" for algo in algos
|
@testset "Avec $algo" for algo in algos
|
||||||
# le cas de test 1
|
# le cas de test 1
|
||||||
xmin,fxmin,flag,nbiters = Lagrangien_Augmente(algo,fct1,contrainte1,grad_fct1,hess_fct1,grad_contrainte1,
|
xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct1, contrainte1, grad_fct1, hess_fct1, grad_contrainte1,
|
||||||
hess_contrainte1,pts2.x01,options)
|
hess_contrainte1, pts2.x01, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("Lagrangien augmenté avec "*algo,"fonction 1","x01",xmin,fxmin,flag,sol_fct1_augm,nbiters)
|
afficher_resultats("Lagrangien augmenté avec " * algo, "fonction 1", "x01", xmin, fxmin, flag, sol_fct1_augm, nbiters)
|
||||||
end
|
end
|
||||||
@test isapprox(xmin,sol_fct1_augm ,atol=tol_erreur)
|
@test isapprox(xmin, sol_fct1_augm, atol = tol_erreur)
|
||||||
|
|
||||||
# le cas de test 2
|
# le cas de test 2
|
||||||
xmin ,fxmin,flag,nbiters = Lagrangien_Augmente(algo,fct1,contrainte1,grad_fct1,hess_fct1,grad_contrainte1,
|
xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct1, contrainte1, grad_fct1, hess_fct1, grad_contrainte1,
|
||||||
hess_contrainte1,pts2.x02,options)
|
hess_contrainte1, pts2.x02, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("Lagrangien augmenté avec "*algo,"fonction 1","x02",xmin,fxmin,flag,sol_fct1_augm,nbiters)
|
afficher_resultats("Lagrangien augmenté avec " * algo, "fonction 1", "x02", xmin, fxmin, flag, sol_fct1_augm, nbiters)
|
||||||
end
|
end
|
||||||
@test xmin ≈ sol_fct1_augm atol=tol_erreur
|
@test xmin ≈ sol_fct1_augm atol = tol_erreur
|
||||||
|
|
||||||
# le cas de test 3
|
# le cas de test 3
|
||||||
xmin,fxmin,flag,nbiters = Lagrangien_Augmente(algo,fct2,contrainte2,grad_fct2,hess_fct2,grad_contrainte2,
|
xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct2, contrainte2, grad_fct2, hess_fct2, grad_contrainte2,
|
||||||
hess_contrainte2,pts2.x03,options)
|
hess_contrainte2, pts2.x03, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("Lagrangien augmenté avec "*algo,"fonction 2","x03",xmin,fxmin,flag,sol_fct2_augm,nbiters)
|
afficher_resultats("Lagrangien augmenté avec " * algo, "fonction 2", "x03", xmin, fxmin, flag, sol_fct2_augm, nbiters)
|
||||||
end
|
end
|
||||||
@test xmin ≈ sol_fct2_augm atol=tol_erreur
|
@test xmin ≈ sol_fct2_augm atol = tol_erreur
|
||||||
|
|
||||||
# le cas de test 4
|
# le cas de test 4
|
||||||
xmin ,fxmin,flag,nbiters = Lagrangien_Augmente(algo,fct2,contrainte2,grad_fct2,hess_fct2,grad_contrainte2,
|
xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct2, contrainte2, grad_fct2, hess_fct2, grad_contrainte2,
|
||||||
hess_contrainte2,pts2.x04,options)
|
hess_contrainte2, pts2.x04, options)
|
||||||
if (afficher)
|
if (afficher)
|
||||||
afficher_resultats("Lagrangien augmenté avec "*algo,"fonction 2","x04",xmin,fxmin,flag,sol_fct2_augm,nbiters)
|
afficher_resultats("Lagrangien augmenté avec " * algo, "fonction 2", "x04", xmin, fxmin, flag, sol_fct2_augm, nbiters)
|
||||||
end
|
end
|
||||||
@test xmin ≈ sol_fct2_augm atol=tol_erreur
|
@test xmin ≈ sol_fct2_augm atol = tol_erreur
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ Tester l'algorithme de pas de Cauchy
|
||||||
* quadratique 2
|
* quadratique 2
|
||||||
* quadratique 3
|
* quadratique 3
|
||||||
"""
|
"""
|
||||||
function tester_pas_de_cauchy(afficher::Bool,Pas_De_Cauchy::Function)
|
function tester_pas_de_cauchy(afficher::Bool, Pas_De_Cauchy::Function)
|
||||||
|
|
||||||
tol_erreur = 1e-6
|
tol_erreur = 1e-6
|
||||||
|
|
||||||
|
@ -18,63 +18,63 @@ function tester_pas_de_cauchy(afficher::Bool,Pas_De_Cauchy::Function)
|
||||||
|
|
||||||
@testset "g = 0" begin
|
@testset "g = 0" begin
|
||||||
g = [0; 0]
|
g = [0; 0]
|
||||||
H = [7 0 ; 0 2]
|
H = [7 0; 0 2]
|
||||||
delta = 1
|
delta = 1
|
||||||
s, e = Pas_De_Cauchy(g,H,delta)
|
s, e = Pas_De_Cauchy(g, H, delta)
|
||||||
@test (e == 0) && (isapprox(s,[0; 0],atol=tol_erreur))
|
@test (e == 0) && (isapprox(s, [0; 0], atol = tol_erreur))
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "quad 2, non saturé" begin
|
@testset "quad 2, non saturé" begin
|
||||||
g = [6; 2]
|
g = [6; 2]
|
||||||
H = [7 0 ; 0 2]
|
H = [7 0; 0 2]
|
||||||
delta = 1
|
delta = 1
|
||||||
s, e = Pas_De_Cauchy(g,H,delta)
|
s, e = Pas_De_Cauchy(g, H, delta)
|
||||||
sol = -(norm(g)^2/(g'*H*g))*g
|
sol = -(norm(g)^2 / (g' * H * g)) * g
|
||||||
@test (e == 1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
@test (e == 1) && (isapprox(s, sol, atol = tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
||||||
end
|
end
|
||||||
@testset "quad 2, saturé" begin
|
@testset "quad 2, saturé" begin
|
||||||
g = [6; 2]
|
g = [6; 2]
|
||||||
H = [7 0 ; 0 2]
|
H = [7 0; 0 2]
|
||||||
delta = 0.9
|
delta = 0.9
|
||||||
s, e = Pas_De_Cauchy(g,H,delta)
|
s, e = Pas_De_Cauchy(g, H, delta)
|
||||||
sol = -(delta/norm(g))*g
|
sol = -(delta / norm(g)) * g
|
||||||
@test (e == -1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
@test (e == -1) && (isapprox(s, sol, atol = tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
||||||
end
|
end
|
||||||
@testset "quad 3, non saturé" begin
|
@testset "quad 3, non saturé" begin
|
||||||
g = [-2; 1]
|
g = [-2; 1]
|
||||||
H = [-2 0 ; 0 10]
|
H = [-2 0; 0 10]
|
||||||
delta = 6
|
delta = 6
|
||||||
s, e = Pas_De_Cauchy(g,H,delta)
|
s, e = Pas_De_Cauchy(g, H, delta)
|
||||||
sol = -(norm(g)^2/(g'*H*g))*g
|
sol = -(norm(g)^2 / (g' * H * g)) * g
|
||||||
println("Cauchy 4 = ", sol)
|
println("Cauchy 4 = ", sol)
|
||||||
@test (e == 1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
@test (e == 1) && (isapprox(s, sol, atol = tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
||||||
end
|
end
|
||||||
@testset "quad 3, saturé" begin
|
@testset "quad 3, saturé" begin
|
||||||
g = [-2; 1]
|
g = [-2; 1]
|
||||||
H = [-2 0 ; 0 10]
|
H = [-2 0; 0 10]
|
||||||
delta = 5
|
delta = 5
|
||||||
s, e = Pas_De_Cauchy(g,H,delta)
|
s, e = Pas_De_Cauchy(g, H, delta)
|
||||||
sol = -(delta/norm(g))*g
|
sol = -(delta / norm(g)) * g
|
||||||
println("Cauchy 5= ", sol)
|
println("Cauchy 5= ", sol)
|
||||||
@test (e == -1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
@test (e == -1) && (isapprox(s, sol, atol = tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
||||||
end
|
end
|
||||||
@testset "quad 3, g'*H*g <0 saturé" begin
|
@testset "quad 3, g'*H*g <0 saturé" begin
|
||||||
g = [3; 1]
|
g = [3; 1]
|
||||||
H = [-2 0 ; 0 10]
|
H = [-2 0; 0 10]
|
||||||
delta = 5
|
delta = 5
|
||||||
s, e = Pas_De_Cauchy(g,H,delta)
|
s, e = Pas_De_Cauchy(g, H, delta)
|
||||||
sol = -(delta/norm(g))*g
|
sol = -(delta / norm(g)) * g
|
||||||
println("Cauchy 6= ", sol)
|
println("Cauchy 6= ", sol)
|
||||||
@test (e == -1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
@test (e == -1) && (isapprox(s, sol, atol = tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
||||||
end
|
end
|
||||||
@testset "quad 3, g'*H*g = 0 saturé" begin
|
@testset "quad 3, g'*H*g = 0 saturé" begin
|
||||||
g = [1,2]
|
g = [1, 2]
|
||||||
H = [2 -1 ; 4 -2]
|
H = [2 -1; 4 -2]
|
||||||
delta = 5
|
delta = 5
|
||||||
s, e = Pas_De_Cauchy(g,H,delta)
|
s, e = Pas_De_Cauchy(g, H, delta)
|
||||||
sol = -(delta/norm(g))*g
|
sol = -(delta / norm(g)) * g
|
||||||
println("Cauchy 6= ", sol)
|
println("Cauchy 6= ", sol)
|
||||||
@test (e == -1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
@test (e == -1) && (isapprox(s, sol, atol = tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue