feat: newton OK
This commit is contained in:
parent
bd31a72072
commit
422543a5f8
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"notebook.output.textLineLimit": 10000
|
||||
}
|
|
@ -14,58 +14,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 66,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[32m\u001b[1m Status\u001b[22m\u001b[39m `~/.julia/environments/v1.7/Project.toml`\n",
|
||||
" \u001b[90m [0c46a032] \u001b[39mDifferentialEquations v6.20.0\n",
|
||||
" \u001b[90m [bd48cda9] \u001b[39mGraphRecipes v0.5.8\n",
|
||||
" \u001b[90m [86223c79] \u001b[39mGraphs v1.4.1\n",
|
||||
" \u001b[90m [91a5bcdd] \u001b[39mPlots v1.25.1\n",
|
||||
" \u001b[90m [a6016688] \u001b[39mTestOptinum v0.1.0 `https://github.com/mathn7/TestOptinum.git#master`\n",
|
||||
" \u001b[90m [37e2e46d] \u001b[39mLinearAlgebra\n",
|
||||
" \u001b[90m [d6f4376e] \u001b[39mMarkdown\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
|
||||
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.7/Project.toml`\n",
|
||||
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.7/Manifest.toml`\n",
|
||||
"\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n",
|
||||
"\u001b[32m ✓ \u001b[39mTestOptinum\n",
|
||||
" 1 dependency successfully precompiled in 3 seconds (262 already precompiled, 2 skipped during auto due to previous errors)\n",
|
||||
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
|
||||
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.7/Project.toml`\n",
|
||||
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.7/Manifest.toml`\n",
|
||||
"\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n",
|
||||
"\u001b[32m ✓ \u001b[39mTestOptinum\n",
|
||||
" 1 dependency successfully precompiled in 3 seconds (262 already precompiled, 2 skipped during auto due to previous errors)\n",
|
||||
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
|
||||
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.7/Project.toml`\n",
|
||||
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.7/Manifest.toml`\n",
|
||||
"\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n",
|
||||
"\u001b[32m ✓ \u001b[39mTestOptinum\n",
|
||||
" 1 dependency successfully precompiled in 3 seconds (262 already precompiled, 2 skipped during auto due to previous errors)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tester_lagrangien_augmente"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"include(\"../test/imports_boilerplate.jl\")"
|
||||
]
|
||||
|
@ -84,133 +35,77 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 67,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct0 au point initial -1.5707963267948966 :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = -1.5707963267948966\n",
|
||||
" * f(xsol) = -1.0\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : -1.5707963267948966\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct0 au point initial -1.0707963267948966 :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = -1.5707963267949088\n",
|
||||
" * f(xsol) = -1.0\n",
|
||||
" * nb_iters = 3\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : -1.5707963267948966\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct0 au point initial 1.5707963267948966 :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = 1.5707963267948966\n",
|
||||
" * f(xsol) = 1.0\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : -1.5707963267948966\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct1 au point initial [1, 1, 1] :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1, 1, 1]\n",
|
||||
" * f(xsol) = 0\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [1, 1, 1]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct1 au point initial [1, 0, 0] :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1.0000000000000002, 1.0, 0.9999999999999998]\n",
|
||||
" * f(xsol) = 9.860761315262648e-32\n",
|
||||
" * nb_iters = 1\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [1, 1, 1]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct1 au point initial [10.0, 3.0, -2.2] :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1.0, 0.9999999999999996, 0.9999999999999982]\n",
|
||||
" * f(xsol) = 1.1832913578315177e-29\n",
|
||||
" * nb_iters = 1\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [1, 1, 1]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct2 au point initial [1, 1] :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1, 1]\n",
|
||||
" * f(xsol) = 0\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [1, 1]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct2 au point initial [-1.2, 1.0] :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [0.9999999999999999, 0.9999999999814724]\n",
|
||||
" * f(xsol) = 3.4326461875363225e-20\n",
|
||||
" * nb_iters = 6\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [1, 1]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Newton appliqué à fct2 au point initial [10, 0] :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1.0, 1.0]\n",
|
||||
" * f(xsol) = 0.0\n",
|
||||
" * nb_iters = 5\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [1, 1]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"options = []\n",
|
||||
"\n",
|
||||
"x0 = sol_exacte_fct0\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct0\", x0, xmin, f_min, flag, sol_exacte_fct0, nb_iters)\n",
|
||||
"x0 = -pi / 2 + 0.5\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct0\", x0, xmin, f_min, flag, sol_exacte_fct0, nb_iters)\n",
|
||||
"x0 = pi / 2\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct0\", x0, xmin, f_min, flag, sol_exacte_fct0, nb_iters)\n",
|
||||
"\n",
|
||||
"x0 = sol_exacte_fct1\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct1\", x0, xmin, f_min, flag, sol_exacte_fct1, nb_iters)\n",
|
||||
"x0 = [1, 0, 0]\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct1\", x0, xmin, f_min, flag, sol_exacte_fct1, nb_iters)\n",
|
||||
"x0 = [10, 3, -2.2]\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad_fct1, hess_fct1, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct1\", x0, xmin, f_min, flag, sol_exacte_fct1, nb_iters)\n",
|
||||
"\n",
|
||||
"x0 = sol_exacte_fct2\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct2\", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)\n",
|
||||
"x0 = [-1.2, 1]\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct2\", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)\n",
|
||||
"x0 = [10, 0]\n",
|
||||
"xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)\n",
|
||||
"afficher_resultats(\"Newton\", \"fct2\", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)\n",
|
||||
"# x0 = [0, 1 / 200 + 1 / 10^12] # explose !\n",
|
||||
"# xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)\n",
|
||||
"# afficher_resultats(\"Newton\", \"fct2\", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 48,
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-0.5463024898437906\n",
|
||||
"0.5463024898437907 1.4901161193847656e-8\n",
|
||||
"0.046335607865117034\n",
|
||||
"0.04633560786511692 1.4901161193847656e-8\n",
|
||||
"-3.311802133838644e-5\n",
|
||||
"3.311802133842967e-5 1.4901161193847656e-8\n",
|
||||
"[1.4802973661668753e-16, 1.0, 0.9999999999999998]\n",
|
||||
"1.414213562373095 1.4901161193847656e-8\n",
|
||||
"[-9.0, -2.0000000000000004, 3.1999999999999984]\n",
|
||||
"9.759098319004682 1.4901161193847656e-8\n",
|
||||
"[0.0247191011235956, 0.3806741573033705]\n",
|
||||
"0.38147588128083515 1.4901161193847656e-8\n",
|
||||
"[1.938395770052605, -4.555708012050932]\n",
|
||||
"4.950944723224334 1.4901161193847656e-8\n",
|
||||
"[0.0003148077076046218, 3.757858630244299]\n",
|
||||
"3.757858643430518 1.4901161193847656e-8\n",
|
||||
"[0.23656563220117438, 0.3612025483564667]\n",
|
||||
"0.43177607538855944 1.4901161193847656e-8\n",
|
||||
"[3.84568678781476e-7, 0.0559640674724924]\n",
|
||||
"0.0559640674738137 1.4901161193847656e-8\n",
|
||||
"[4.304346341338872e-6, 8.608655775764598e-6]\n",
|
||||
"9.624778007431938e-6 1.4901161193847656e-8\n",
|
||||
"[-0.0004499775011251476, 99.99100044997749]\n",
|
||||
"99.99100045098997 1.4901161193847656e-8\n",
|
||||
"[-8.99918559194064, -179.97561277424336]\n",
|
||||
"180.20046208260007 1.4901161193847656e-8\n",
|
||||
"[-2.2498396305867807e-8, 80.98534127317878]\n",
|
||||
"80.98534127317878 1.4901161193847656e-8\n",
|
||||
"[-0.0003644080598389195, -0.0007290817061411055]\n",
|
||||
"0.0008150787497567694 1.4901161193847656e-8\n",
|
||||
"[-4.4407648973031725e-16, 1.3279323318740367e-7]\n",
|
||||
"1.3279323318737823e-7 1.4901161193847656e-8\n",
|
||||
"[-4.99999958629818e9, -0.005000000001]\n",
|
||||
"4.99999958629818e9 1.4901161193847656e-8\n",
|
||||
"[-4.99999958629818e9, -0.005000000001]\n",
|
||||
"4.99999958629818e9 1.4901161193847656e-8\n",
|
||||
"[6.004800496839379e-7, 2.499999586298196e19]\n",
|
||||
"2.499999586298196e19 4.99999958629818e-6\n",
|
||||
"[-3518.437500703689, 3.518437209586888e13]\n",
|
||||
"3.5184372097024e13 24999.995862981963\n",
|
||||
"[2.0220898268939407, -2.0208532713048275e10]\n",
|
||||
"2.0208533504e10 25000.03104735406\n",
|
||||
"[-1.0e-9, -1.0e-9, -1.0e-9]\n",
|
||||
"1.732050758583135e-9 1.4901161193847656e-8\n",
|
||||
"[-4.9999974749156296e-5, 9899.99000000505]\n",
|
||||
"9899.99000000505 1.4901161193847656e-8\n",
|
||||
"[-98.99990041369064, -19799.970182750585]\n",
|
||||
"19800.217681078513 1.4901161193847656e-8\n",
|
||||
"[-2.529670807346846e-11, 9800.980281920612]\n",
|
||||
"9800.980281920612 1.4901161193847656e-8\n",
|
||||
"[-4.95863093076493e-5, -9.917753547159461e-5]\n",
|
||||
"0.0001108827561570618 1.4901161193847656e-8\n",
|
||||
"[0.0247191011235956, 0.3806741573033705]\n",
|
||||
"0.38147588128083515 1.4901161193847656e-8\n",
|
||||
"[1.938395770052605, -4.555708012050932]\n",
|
||||
"4.950944723224334 1.4901161193847656e-8\n",
|
||||
"\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n",
|
||||
"L'algo de Newton | \u001b[32m 14 \u001b[39m\u001b[36m 14\u001b[39m\n"
|
||||
"L'algo de Newton | \u001b[32m 24 \u001b[39m\u001b[36m 24\u001b[39m\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Test.DefaultTestSet(\"L'algo de Newton\", Any[Test.DefaultTestSet(\"Cas test 1 x0 = solution\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 1 x0 = x011\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 1 x0 = x012\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = solution\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x021\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x022\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x023\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"exception\", Any[], 1, false, false)], 0, false, false)], 0, false, false)"
|
||||
"Test.DefaultTestSet(\"L'algo de Newton\", Any[Test.DefaultTestSet(\"Cas test 0 x0 = solution\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 0 x0 = x001\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 0 x0 = x002\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 1 x0 = solution\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 1 x0 = x011\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 1 x0 = x012\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = solution\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x021\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x022\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"itération\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test 2 x0 = x023\", Any[Test.DefaultTestSet(\"solution\", Any[], 1, false, false), Test.DefaultTestSet(\"exception\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test stagnation x\", Any[Test.DefaultTestSet(\"flag\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test stagnation f(x)\", Any[Test.DefaultTestSet(\"flag\", Any[], 1, false, false)], 0, false, false), Test.DefaultTestSet(\"Cas test itermax\", Any[Test.DefaultTestSet(\"itération\", Any[], 1, false, false), Test.DefaultTestSet(\"flag\", Any[], 1, false, false)], 0, false, false)], 0, false, false)"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
|
@ -272,28 +167,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 49,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Cauchy 1\u001b[22m\u001b[39m\n",
|
||||
" * s = [0, 0]\n",
|
||||
" * e = 0\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Cauchy 2\u001b[22m\u001b[39m\n",
|
||||
" * s = [-0.9230769230769234, -0.30769230769230776]\n",
|
||||
" * e = 1\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Cauchy 3\u001b[22m\u001b[39m\n",
|
||||
" * s = [0.8944271909999159, -0.4472135954999579]\n",
|
||||
" * e = -1\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function my_afficher_resultats_cauchy(algo, s, e)\n",
|
||||
" println(\"-------------------------------------------------------------------------\")\n",
|
||||
|
@ -323,68 +199,18 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 50,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Cauchy 4 = [5.000000000000001, -2.5000000000000004]\n",
|
||||
"Cauchy 5= [4.47213595499958, -2.23606797749979]\n",
|
||||
"Cauchy 6= [-4.743416490252569, -1.5811388300841895]\n",
|
||||
"Cauchy 6= [-2.23606797749979, -4.47213595499958]\n",
|
||||
"\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n",
|
||||
"Pas de Cauchy | \u001b[32m 7 \u001b[39m\u001b[36m 7\u001b[39m\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Test.DefaultTestSet(\"Pas de Cauchy\", Any[Test.DefaultTestSet(\"g = 0\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 2, non saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 2, saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 3, non saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 3, saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 3, g'*H*g <0 saturé\", Any[], 1, false, false), Test.DefaultTestSet(\"quad 3, g'*H*g = 0 saturé\", Any[], 1, false, false)], 0, false, false)"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tester_pas_de_cauchy(false, Pas_De_Cauchy)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 51,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : RC-Cauchy appliqué à f0 au point initial -1.5707963267948966:\u001b[22m\u001b[39m\n",
|
||||
" * xsol = -1.5707963267948966\n",
|
||||
" * f(xsol) = -1.0\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : -1.5707963267948966\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : RC-Cauchy appliqué à f1 au point initial [1, 1, 1]:\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1, 1, 1]\n",
|
||||
" * f(xsol) = 0\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [1, 1, 1]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : RC-Cauchy appliqué à f2 au point initial [1.0, 0.01]:\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1.0, 0.01]\n",
|
||||
" * f(xsol) = 0.0\n",
|
||||
" * nb_iters = 10000\n",
|
||||
" * flag = 3\n",
|
||||
" * sol_exacte : [1.0, 0.01]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"options = [10, 0.5, 2.00, 0.25, 0.75, 2, 10000, sqrt(eps()), 1e-15]\n",
|
||||
"algo = \"cauchy\"\n",
|
||||
|
@ -441,31 +267,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 52,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Cauchy 1\u001b[22m\u001b[39m\n",
|
||||
" * s = [2.220446049250313e-16, 1.0]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Cauchy 2\u001b[22m\u001b[39m\n",
|
||||
" * s = [0.0, 0.0]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Cauchy 3\u001b[22m\u001b[39m\n",
|
||||
" * s = [-0.4743416490252569, -0.15811388300841897]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Cauchy 4\u001b[22m\u001b[39m\n",
|
||||
" * s = [-0.8740776099190263, -0.8221850958502243]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Cauchy 5\u001b[22m\u001b[39m\n",
|
||||
" * s = [-0.8571428571428571, -0.9999999999999998]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function my_afficher_resultats_gct(algo, s)\n",
|
||||
" println(\"-------------------------------------------------------------------------\")\n",
|
||||
|
@ -506,64 +310,18 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 53,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n",
|
||||
"Gradient-CT | \u001b[32m 9 \u001b[39m\u001b[36m 9\u001b[39m\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Test.DefaultTestSet(\"Gradient-CT\", Any[], 9, false, false)"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tester_gct(false, Gradient_Conjugue_Tronque)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 54,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : RC-GCT appliqué à f0 au point initial -1.5707963267948966:\u001b[22m\u001b[39m\n",
|
||||
" * xsol = -1.5707963267948966\n",
|
||||
" * f(xsol) = -1.0\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : -1.5707963267948966\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : RC-GCT appliqué à f1 au point initial [1, 1, 1]:\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1, 1, 1]\n",
|
||||
" * f(xsol) = 0\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [1, 1, 1]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : RC-GCT appliqué à f2 au point initial [1.0, 0.01]:\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [1.0, 0.01]\n",
|
||||
" * f(xsol) = 0.0\n",
|
||||
" * nb_iters = 10000\n",
|
||||
" * flag = 3\n",
|
||||
" * sol_exacte : [1.0, 0.01]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"options = [10, 0.5, 2.00, 0.25, 0.75, 2, 10000, sqrt(eps()), 1e-15]\n",
|
||||
"algo = \"gct\"\n",
|
||||
|
@ -583,28 +341,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 55,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"iters = 864\n",
|
||||
"\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n",
|
||||
"La méthode des RC | \u001b[32m 10 \u001b[39m\u001b[36m 10\u001b[39m\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Test.DefaultTestSet(\"La méthode des RC \", Any[Test.DefaultTestSet(\"avec Cauchy \", Any[], 5, false, false), Test.DefaultTestSet(\"avec GCT \", Any[], 5, false, false)], 0, false, false)"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tester_regions_de_confiance(false, Regions_De_Confiance)"
|
||||
]
|
||||
|
@ -657,37 +396,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 56,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Lagrangien augmenté avec newton appliqué à fonction 1 au point initial x01 :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [0, 1, 1]\n",
|
||||
" * f(xsol) = 3\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [0.5, 1.25, 0.5]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Lagrangien augmenté avec cauchy appliqué à fonction 1 au point initial x01 :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [0, 1, 1]\n",
|
||||
" * f(xsol) = 3\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [0.5, 1.25, 0.5]\n",
|
||||
"-------------------------------------------------------------------------\n",
|
||||
"\u001b[34m\u001b[1mRésultats de : Lagrangien augmenté avec gct appliqué à fonction 1 au point initial x01 :\u001b[22m\u001b[39m\n",
|
||||
" * xsol = [0, 1, 1]\n",
|
||||
" * f(xsol) = 3\n",
|
||||
" * nb_iters = 0\n",
|
||||
" * flag = 0\n",
|
||||
" * sol_exacte : [0.5, 1.25, 0.5]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function afficher_resultats(algo,nom_fct,point_init,xmin,fxmin,flag,sol_exacte,nbiters)\n",
|
||||
"\tprintln(\"-------------------------------------------------------------------------\")\n",
|
||||
|
@ -737,61 +448,18 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 57,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\u001b[0m\u001b[1mTest Summary: | \u001b[22m\u001b[32m\u001b[1mPass \u001b[22m\u001b[39m\u001b[36m\u001b[1mTotal\u001b[22m\u001b[39m\n",
|
||||
"Lagrangien augmenté | \u001b[32m 12 \u001b[39m\u001b[36m 12\u001b[39m\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"Test.DefaultTestSet(\"Lagrangien augmenté \", Any[Test.DefaultTestSet(\"Avec newton\", Any[], 4, false, false), Test.DefaultTestSet(\"Avec gct\", Any[], 4, false, false), Test.DefaultTestSet(\"Avec cauchy\", Any[], 4, false, false)], 0, false, false)"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tester_lagrangien_augmente(false, Lagrangien_Augmente)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 58,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"algo=newton, tau=0.01 \t--> iter=100 fxmin=11.111111108395063 flag=1\n",
|
||||
"algo=newton, tau=0.1 \t--> iter=100 fxmin=11.111111108395065 flag=1\n",
|
||||
"algo=newton, tau=1.0 \t--> iter=100 fxmin=4.280618311533889 flag=1\n",
|
||||
"algo=newton, tau=10.0 \t--> iter=5 fxmin=2.250000814411402 flag=0\n",
|
||||
"algo=newton, tau=100.0 \t--> iter=4 fxmin=2.2500000022152014 flag=0\n",
|
||||
"algo=newton, tau=1000.0 \t--> iter=3 fxmin=2.2500000005005116 flag=0\n",
|
||||
"algo=cauchy, tau=0.01 \t--> iter=100 fxmin=9.972299093706013 flag=1\n",
|
||||
"algo=cauchy, tau=0.1 \t--> iter=100 fxmin=9.972299137559094 flag=1\n",
|
||||
"algo=cauchy, tau=1.0 \t--> iter=100 fxmin=4.058286995337872 flag=1\n",
|
||||
"algo=cauchy, tau=10.0 \t--> iter=100 fxmin=2.2502165830370076 flag=1\n",
|
||||
"algo=cauchy, tau=100.0 \t--> iter=100 fxmin=2.314845242402915 flag=1\n",
|
||||
"algo=cauchy, tau=1000.0 \t--> iter=100 fxmin=2.412284973385117 flag=1\n",
|
||||
"algo=gct, tau=0.01 \t--> iter=100 fxmin=11.111111108395058 flag=1\n",
|
||||
"algo=gct, tau=0.1 \t--> iter=100 fxmin=11.111110839506175 flag=1\n",
|
||||
"algo=gct, tau=1.0 \t--> iter=100 fxmin=4.280618311533889 flag=1\n",
|
||||
"algo=gct, tau=10.0 \t--> iter=5 fxmin=2.250000814411402 flag=0\n",
|
||||
"algo=gct, tau=100.0 \t--> iter=4 fxmin=2.250000002215201 flag=0\n",
|
||||
"algo=gct, tau=1000.0 \t--> iter=3 fxmin=2.2500000005005116 flag=0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for algo in [\"newton\" \"cauchy\" \"gct\"]\n",
|
||||
" for tau in [0.01; 0.1; 1; 10; 100; 1000]\n",
|
||||
|
@ -821,52 +489,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 59,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"-----------------------------------------\n",
|
||||
"algo=newton, tau=0.01 \t--> iter=100 fxmin=11.111111108395063 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=newton, tau=0.1 \t--> iter=100 fxmin=11.111111108395065 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=newton, tau=1.0 \t--> iter=100 fxmin=4.280618311533889 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=newton, tau=10.0 \t--> iter=5 fxmin=2.250000814411402 flag=0\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=newton, tau=100.0 \t--> iter=4 fxmin=2.2500000022152014 flag=0\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=newton, tau=1000.0 \t--> iter=3 fxmin=2.2500000005005116 flag=0\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=cauchy, tau=0.01 \t--> iter=100 fxmin=9.972299093706013 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=cauchy, tau=0.1 \t--> iter=100 fxmin=9.972299137559094 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=cauchy, tau=1.0 \t--> iter=100 fxmin=4.058286995337872 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=cauchy, tau=10.0 \t--> iter=100 fxmin=2.2502165830370076 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=cauchy, tau=100.0 \t--> iter=100 fxmin=2.314845242402915 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=cauchy, tau=1000.0 \t--> iter=100 fxmin=2.412284973385117 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=gct, tau=0.01 \t--> iter=100 fxmin=11.111111108395058 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=gct, tau=0.1 \t--> iter=100 fxmin=11.111110839506175 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=gct, tau=1.0 \t--> iter=100 fxmin=4.280618311533889 flag=1\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=gct, tau=10.0 \t--> iter=5 fxmin=2.250000814411402 flag=0\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=gct, tau=100.0 \t--> iter=4 fxmin=2.250000002215201 flag=0\n",
|
||||
"-----------------------------------------\n",
|
||||
"algo=gct, tau=1000.0 \t--> iter=3 fxmin=2.2500000005005116 flag=0\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"for algo in [\"newton\" \"cauchy\" \"gct\"]\n",
|
||||
" for tau in [0.01; 0.1; 1; 10; 100; 1000]\n",
|
||||
|
|
|
@ -8,6 +8,8 @@ Ce fichier contient toutes fonctions utilisés dans les tests des algorithmes :
|
|||
# Les points initiaux
|
||||
## pour les problèmes sans contraintes
|
||||
struct Pts_sans_contraintes
|
||||
x001
|
||||
x002
|
||||
x011
|
||||
x012
|
||||
x021
|
||||
|
@ -15,6 +17,8 @@ struct Pts_sans_contraintes
|
|||
x023
|
||||
end
|
||||
pts1 = Pts_sans_contraintes(
|
||||
-pi / 2 + 0.5,
|
||||
pi / 2,
|
||||
[1; 0; 0],
|
||||
[10; 3; -2.2],
|
||||
[-1.2; 1],
|
||||
|
@ -119,7 +123,7 @@ hess_contrainte2(x) = [2 0; 0 2]
|
|||
|
||||
# Affichage les sorties de l'algorithme des Régions de confiance
|
||||
function 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)
|
||||
println(" * xsol = ", xmin)
|
||||
println(" * f(xsol) = ", fxmin)
|
||||
|
|
|
@ -21,7 +21,7 @@ include("../src/Regions_De_Confiance.jl")
|
|||
# Tolérance pour les tests d'égalité
|
||||
tol_erreur = sqrt(eps())
|
||||
|
||||
## ajouter les fonctions de test
|
||||
# ajouter les fonctions de test
|
||||
include("fonctions_de_tests.jl")
|
||||
include("tester_algo_newton.jl")
|
||||
include("tester_pas_de_cauchy.jl")
|
||||
|
|
|
@ -14,11 +14,54 @@ function tester_algo_newton(afficher::Bool, Algorithme_De_Newton::Function)
|
|||
Tol_rel = 1e-15
|
||||
options = [max_iter, Tol_abs, Tol_rel]
|
||||
@testset "L'algo de Newton" begin
|
||||
|
||||
# tests sur la fonction fct0
|
||||
@testset "Cas test 0 x0 = solution" begin
|
||||
# point de départ sol_exacte
|
||||
xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, sol_exacte_fct0, options)
|
||||
if (afficher)
|
||||
afficher_resultats("algorithme de Newton", "fct0", "sol_exacte", xmin, f_min, flag, sol_exacte_fct0, nb_iters)
|
||||
end
|
||||
@testset "solution" begin
|
||||
@test isapprox(xmin, sol_exacte_fct0, atol = tol_erreur)
|
||||
end
|
||||
@testset "itération" begin
|
||||
@test nb_iters == 0
|
||||
end
|
||||
end
|
||||
@testset "Cas test 0 x0 = x001" begin
|
||||
#point de départ x001
|
||||
xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, pts1.x001, options)
|
||||
if (afficher)
|
||||
afficher_resultats("algorithme de Newton", "fct0", "x001", xmin, f_min, flag, sol_exacte_fct0, nb_iters)
|
||||
end
|
||||
@testset "solution" begin
|
||||
@test isapprox(xmin, sol_exacte_fct0, atol = tol_erreur)
|
||||
end
|
||||
@testset "itération" begin
|
||||
@test nb_iters == 3
|
||||
end
|
||||
end
|
||||
@testset "Cas test 0 x0 = x002" begin
|
||||
#point de départ x002 = -sol_exacte_fct0
|
||||
xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct0, grad_fct0, hess_fct0, pts1.x002, options)
|
||||
if (afficher)
|
||||
afficher_resultats("algorithme de Newton", "fct0", "x002", xmin, f_min, flag, sol_exacte_fct0, nb_iters)
|
||||
end
|
||||
@testset "solution" begin
|
||||
@test isapprox(xmin, -sol_exacte_fct0, atol = tol_erreur)
|
||||
end
|
||||
@testset "itération" begin
|
||||
@test nb_iters == 0
|
||||
end
|
||||
end
|
||||
|
||||
# tests sur la fonction fct1
|
||||
@testset "Cas test 1 x0 = solution" begin
|
||||
# point de départ x011
|
||||
# point de départ sol_exacte
|
||||
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)
|
||||
afficher_resultats("algorithme de Newton", "fct1", "sol_exacte", x_min, fx_min, flag, sol_exacte_fct1, nb_iters)
|
||||
end
|
||||
@testset "solution" begin
|
||||
@test isapprox(x_min, sol_exacte_fct1, atol = tol_erreur)
|
||||
|
@ -31,7 +74,7 @@ function tester_algo_newton(afficher::Bool, Algorithme_De_Newton::Function)
|
|||
#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)
|
||||
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)
|
||||
|
@ -43,19 +86,21 @@ function tester_algo_newton(afficher::Bool, Algorithme_De_Newton::Function)
|
|||
@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)
|
||||
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
|
||||
@test isapprox(x_min, sol_exacte_fct1, atol = tol_erreur)
|
||||
end
|
||||
@testset "itération" begin
|
||||
@test nb_iters == 1
|
||||
end
|
||||
end
|
||||
|
||||
# tests sur la fonction fct2
|
||||
@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)
|
||||
afficher_resultats("algorithme de Newton", "fct1", "sol_exacte", x_min, fx_min, flag, sol_exacte_fct1, nb_iters)
|
||||
end
|
||||
@testset "solution" begin
|
||||
@test isapprox(x_min, sol_exacte_fct1, atol = tol_erreur)
|
||||
|
@ -67,10 +112,10 @@ function tester_algo_newton(afficher::Bool, Algorithme_De_Newton::Function)
|
|||
@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)
|
||||
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
|
||||
@test isapprox(x_min, sol_exacte_fct2, atol = tol_erreur)
|
||||
end
|
||||
@testset "itération" begin
|
||||
@test nb_iters == 6
|
||||
|
@ -79,30 +124,78 @@ function tester_algo_newton(afficher::Bool, Algorithme_De_Newton::Function)
|
|||
@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)
|
||||
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
|
||||
@test isapprox(x_min, sol_exacte_fct2, atol = tol_erreur)
|
||||
end
|
||||
@testset "itération" begin
|
||||
@test nb_iters == 5
|
||||
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", "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
|
||||
@testset "solution" begin
|
||||
@test x_min ≈ sol atol = tol_erreur
|
||||
@test isapprox(x_min, sol, atol = tol_erreur)
|
||||
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
|
||||
|
||||
# vérification de tous les flags
|
||||
@testset "Cas test stagnation x" begin
|
||||
max_iter = 1000
|
||||
Tol_abs = sqrt(eps())
|
||||
Tol_rel = 1e-15
|
||||
options = [max_iter, Tol_abs, Tol_rel]
|
||||
hess(x) = [
|
||||
1e10 0 0
|
||||
0 1e10 0
|
||||
0 0 1e10
|
||||
]
|
||||
grad(x) = [
|
||||
10
|
||||
10
|
||||
10
|
||||
]
|
||||
x0 = ones(3) .* 0.9999
|
||||
xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct1, grad, hess, x0, options)
|
||||
if (afficher)
|
||||
afficher_resultats("stagnation x de Newton", "fct0", x0, xmin, f_min, flag, sol_exacte_fct0, nb_iters)
|
||||
end
|
||||
@testset "flag" begin
|
||||
@test flag == 1
|
||||
end
|
||||
end
|
||||
@testset "Cas test stagnation f(x)" begin
|
||||
x0 = ones(2) .* 100
|
||||
xmin, f_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, x0, options)
|
||||
if (afficher)
|
||||
afficher_resultats("stagnation f(x) de Newton", "fct2", x0, xmin, f_min, flag, sol_exacte_fct2, nb_iters)
|
||||
end
|
||||
@testset "flag" begin
|
||||
@test flag == 2
|
||||
end
|
||||
end
|
||||
@testset "Cas test itermax" begin
|
||||
options[1] = 2
|
||||
x_min, fx_min, flag, nb_iters = Algorithme_De_Newton(fct2, grad_fct2, hess_fct2, pts1.x021, options)
|
||||
if (afficher)
|
||||
afficher_resultats("itermax de Newton", "fct2", "x021", x_min, fx_min, flag, sol_exacte_fct2, nb_iters)
|
||||
end
|
||||
@testset "itération" begin
|
||||
@test nb_iters == 2
|
||||
end
|
||||
@testset "flag" begin
|
||||
@test flag == 3
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ function tester_lagrangien_augmente(afficher::Bool, Lagrangien_Augmente::Functio
|
|||
if (afficher)
|
||||
afficher_resultats("Lagrangien augmenté avec " * algo, "fonction 1", "x02", xmin, fxmin, flag, sol_fct1_augm, nbiters)
|
||||
end
|
||||
@test xmin ≈ sol_fct1_augm atol = tol_erreur
|
||||
@test isapprox(xmin, sol_fct1_augm, atol = tol_erreur)
|
||||
|
||||
# le cas de test 3
|
||||
xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct2, contrainte2, grad_fct2, hess_fct2, grad_contrainte2,
|
||||
|
@ -55,7 +55,7 @@ function tester_lagrangien_augmente(afficher::Bool, Lagrangien_Augmente::Functio
|
|||
if (afficher)
|
||||
afficher_resultats("Lagrangien augmenté avec " * algo, "fonction 2", "x03", xmin, fxmin, flag, sol_fct2_augm, nbiters)
|
||||
end
|
||||
@test xmin ≈ sol_fct2_augm atol = tol_erreur
|
||||
@test isapprox(xmin, sol_fct2_augm, atol = tol_erreur)
|
||||
|
||||
# le cas de test 4
|
||||
xmin, fxmin, flag, nbiters = Lagrangien_Augmente(algo, fct2, contrainte2, grad_fct2, hess_fct2, grad_contrainte2,
|
||||
|
@ -63,7 +63,7 @@ function tester_lagrangien_augmente(afficher::Bool, Lagrangien_Augmente::Functio
|
|||
if (afficher)
|
||||
afficher_resultats("Lagrangien augmenté avec " * algo, "fonction 2", "x04", xmin, fxmin, flag, sol_fct2_augm, nbiters)
|
||||
end
|
||||
@test xmin ≈ sol_fct2_augm atol = tol_erreur
|
||||
@test isapprox(xmin, sol_fct2_augm, atol = tol_erreur)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,14 +49,14 @@ function tester_regions_de_confiance(afficher::Bool, Regions_De_Confiance::Funct
|
|||
if (afficher)
|
||||
afficher_resultats("régions de confiance avec " * "cauchy", "fonction 1", "x012", x_min12, fmin12, flag11, sol_exacte_fct1, nb_iters12)
|
||||
end
|
||||
@test x_min12 ≈ sol_exacte_fct1 atol = tol_erreur
|
||||
@test isapprox(x_min12, sol_exacte_fct1, atol = tol_erreur)
|
||||
|
||||
# cas de test 3
|
||||
x_min21, fmin21, flag21, nb_iters21, = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x021, options2)
|
||||
if (afficher)
|
||||
afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x021", x_min21, fmin21, flag21, sol_exacte_fct2, nb_iters21)
|
||||
end
|
||||
@test x_min21 ≈ sol_exacte_fct2 atol = tol_erreur
|
||||
@test isapprox(x_min21, sol_exacte_fct2, atol = tol_erreur)
|
||||
|
||||
# cas de test 4
|
||||
x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x022, options2)
|
||||
|
@ -64,14 +64,14 @@ function tester_regions_de_confiance(afficher::Bool, Regions_De_Confiance::Funct
|
|||
if (afficher)
|
||||
afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x022", x_min22, fmin22, flag22, sol_exacte_fct2, nb_iters22)
|
||||
end
|
||||
@test x_min22 ≈ sol_exacte_fct2 atol = tol_erreur
|
||||
@test isapprox(x_min22, sol_exacte_fct2, atol = tol_erreur)
|
||||
|
||||
# cas de test 5
|
||||
x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("cauchy", fct2, grad_fct2, hess_fct2, pts1.x023, options2)
|
||||
if (afficher)
|
||||
afficher_resultats("régions de confiance avec " * "cauchy", "fonction 2", "x023", x_min23, fmin23, flag23, sol_exacte_fct2, nb_iters23)
|
||||
end
|
||||
@test x_min23 ≈ sol_exacte_fct2 atol = tol_erreur
|
||||
@test isapprox(x_min23, sol_exacte_fct2, atol = tol_erreur)
|
||||
end
|
||||
|
||||
###################################################
|
||||
|
@ -91,28 +91,28 @@ function tester_regions_de_confiance(afficher::Bool, Regions_De_Confiance::Funct
|
|||
if (afficher)
|
||||
afficher_resultats("régions de confiance avec " * "gct", "fonction 1", "x012", x_min12, fmin12, flag12, sol_exacte_fct1, nb_iters12)
|
||||
end
|
||||
@test x_min12 ≈ sol_exacte_fct1 atol = tol_erreur
|
||||
@test isapprox(x_min12, sol_exacte_fct1, atol = tol_erreur)
|
||||
|
||||
# cas de test 3
|
||||
x_min21, fmin21, flag21, nb_iters21 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x021, options2)
|
||||
if (afficher)
|
||||
afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x021", x_min21, fmin21, flag21, sol_exacte_fct2, nb_iters21)
|
||||
end
|
||||
@test x_min21 ≈ sol_exacte_fct2 atol = tol_erreur
|
||||
@test isapprox(x_min21, sol_exacte_fct2, atol = tol_erreur)
|
||||
|
||||
# cas de test 4
|
||||
x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x022, options2)
|
||||
if (afficher)
|
||||
afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x022", x_min22, fmin22, flag22, sol_exacte_fct2, nb_iters22)
|
||||
end
|
||||
@test x_min22 ≈ sol_exacte_fct2 atol = tol_erreur
|
||||
@test isapprox(x_min22, sol_exacte_fct2, atol = tol_erreur)
|
||||
|
||||
# cas de test 5
|
||||
x_min23, fmin23, flag23, nb_iters23 = Regions_De_Confiance("gct", fct2, grad_fct2, hess_fct2, pts1.x023, options2)
|
||||
if (afficher)
|
||||
afficher_resultats("régions de confiance avec " * "gct", "fonction 2", "x023", x_min11, fmin23, flag23, sol_exacte_fct2, nb_iters23)
|
||||
end
|
||||
@test x_min23 ≈ sol_exacte_fct2 atol = tol_erreur
|
||||
@test isapprox(x_min23, sol_exacte_fct2, atol = tol_erreur)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue