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
59d0506e
Commit
59d0506e
authored
2 years ago
by
Olivier Cots
Browse files
Options
Downloads
Patches
Plain Diff
foo
parent
8b96b264
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/tester_algo_newton.jl
+119
-119
119 additions, 119 deletions
test/tester_algo_newton.jl
with
119 additions
and
119 deletions
test/tester_algo_newton.jl
+
119
−
119
View file @
59d0506e
...
...
@@ -8,126 +8,126 @@ Tester l'algorithme de Newton local
* fct 1 : x011, x012
* fct 2 : x021, x022, x023
"""
function
tester_algo_newton
(
afficher
::
Bool
,
Algorithme_De_Newton
::
Function
)
max_iter
=
100
function
tester_algo_newton
(
afficher
::
Bool
,
Algorithme_De_Newton
::
Function
)
max_iter
=
100
Tol_abs
=
sqrt
(
eps
())
Tol_rel
=
1e-15
epsilon
=
1.
options
=
[
max_iter
,
Tol_abs
,
Tol_rel
,
epsilon
]
@testset
"L'algo de Newton"
begin
@testset
"Cas test 1 x0 = solution"
begin
# point de départ x011
x_min
,
fx_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
fct1
,
grad_fct1
,
hess_fct1
,
sol_exacte_fct1
,
options
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct1"
,
"x011"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct1
,
nb_iters
)
end
@testset
"solution"
begin
@test
isapprox
(
x_min
,
sol_exacte_fct1
,
atol
=
tol_erreur
)
end
@testset
"itération"
begin
@test
nb_iters
==
0
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@testset
"Cas test 1 x0 = x011"
begin
#point de départ x011
x_min
,
fx_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
fct1
,
grad_fct1
,
hess_fct1
,
pts1
.
x011
,
options
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct1"
,
"x011"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct1
,
nb_iters
)
end
@testset
"solution"
begin
@test
isapprox
(
x_min
,
sol_exacte_fct1
,
atol
=
tol_erreur
)
end
@testset
"itération"
begin
@test
nb_iters
==
1
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@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
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct1"
,
"x012"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct1
,
nb_iters
)
end
@testset
"solution"
begin
@test
x_min
≈
sol_exacte_fct1
atol
=
tol_erreur
end
@testset
"itération"
begin
@test
nb_iters
==
1
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@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
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct1"
,
"x011"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct1
,
nb_iters
)
end
@testset
"solution"
begin
@test
isapprox
(
x_min
,
sol_exacte_fct1
,
atol
=
tol_erreur
)
end
@testset
"itération"
begin
@test
nb_iters
==
0
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@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
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct2"
,
"x021"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct2
,
nb_iters
)
end
@testset
"solution"
begin
@test
x_min
≈
sol_exacte_fct2
atol
=
tol_erreur
end
@testset
"itération"
begin
@test
nb_iters
==
6
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@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
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct2"
,
"x022"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct2
,
nb_iters
)
end
@testset
"solution"
begin
@test
x_min
≈
sol_exacte_fct2
atol
=
tol_erreur
end
@testset
"itération"
begin
@test
nb_iters
==
5
end
@testset
"flag"
begin
@test
flag
==
0
end
end
epsilon
=
1.
0
options
=
[
max_iter
,
Tol_abs
,
Tol_rel
,
epsilon
]
@testset
"L'algo de Newton"
begin
@testset
"Cas test 1 x0 = solution"
begin
# point de départ x011
x_min
,
fx_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
fct1
,
grad_fct1
,
hess_fct1
,
sol_exacte_fct1
,
options
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct1"
,
"x011"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct1
,
nb_iters
)
end
@testset
"solution"
begin
@test
isapprox
(
x_min
,
sol_exacte_fct1
,
atol
=
tol_erreur
)
end
@testset
"itération"
begin
@test
nb_iters
==
0
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@testset
"Cas test 1 x0 = x011"
begin
#point de départ x011
x_min
,
fx_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
fct1
,
grad_fct1
,
hess_fct1
,
pts1
.
x011
,
options
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct1"
,
"x011"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct1
,
nb_iters
)
end
@testset
"solution"
begin
@test
isapprox
(
x_min
,
sol_exacte_fct1
,
atol
=
tol_erreur
)
end
@testset
"itération"
begin
@test
nb_iters
==
1
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@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
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct1"
,
"x012"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct1
,
nb_iters
)
end
@testset
"solution"
begin
@test
x_min
≈
sol_exacte_fct1
atol
=
tol_erreur
end
@testset
"itération"
begin
@test
nb_iters
==
1
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@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
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct1"
,
"x011"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct1
,
nb_iters
)
end
@testset
"solution"
begin
@test
isapprox
(
x_min
,
sol_exacte_fct1
,
atol
=
tol_erreur
)
end
@testset
"itération"
begin
@test
nb_iters
==
0
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@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
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct2"
,
"x021"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct2
,
nb_iters
)
end
@testset
"solution"
begin
@test
x_min
≈
sol_exacte_fct2
atol
=
tol_erreur
end
@testset
"itération"
begin
@test
nb_iters
==
6
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@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
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct2"
,
"x022"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct2
,
nb_iters
)
end
@testset
"solution"
begin
@test
x_min
≈
sol_exacte_fct2
atol
=
tol_erreur
end
@testset
"itération"
begin
@test
nb_iters
==
5
end
@testset
"flag"
begin
@test
flag
==
0
end
end
@testset
"Cas test 2 x0 = x023"
begin
options
[
1
]
=
1
sol
=
[
-
4.99999958629818e9
,
8.673617379884035e-19
]
x_min
,
fx_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
fct2
,
grad_fct2
,
hess_fct2
,
pts1
.
x023
,
options
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct2"
,
"x023"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct2
,
nb_iters
)
end
@testset
"solution"
begin
@test
x_min
≈
sol
atol
=
tol_erreur
end
@testset
"flag"
begin
@test
flag
==
3
end
@testset
"itération"
begin
@test
nb_iters
==
1
end
@testset
"exception"
begin
options
[
1
]
=
100
@test_throws
SingularException
x_min
,
fx_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
fct2
,
grad_fct2
,
hess_fct2
,
pts1
.
x023
,
options
)
end
end
end
@testset
"Cas test 2 x0 = x023"
begin
options
[
1
]
=
1
sol
=
[
-
4.99999958629818e9
,
8.673617379884035e-19
]
x_min
,
fx_min
,
flag
,
nb_iters
=
Algorithme_De_Newton
(
fct2
,
grad_fct2
,
hess_fct2
,
pts1
.
x023
,
options
)
if
(
afficher
)
afficher_resultats
(
"algorithme de Newton "
,
"fct2"
,
"x023"
,
x_min
,
fx_min
,
flag
,
sol_exacte_fct2
,
nb_iters
)
end
@testset
"solution"
begin
@test
x_min
≈
sol
atol
=
tol_erreur
end
@testset
"flag"
begin
@test
flag
==
3
end
@testset
"itération"
begin
@test
nb_iters
==
1
end
@testset
"exception"
begin
options
[
1
]
=
100
@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
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