Skip to content
Snippets Groups Projects
Commit 2eb7fc63 authored by Gergaud's avatar Gergaud
Browse files

ajout des tests unitaire dans optinum

parent db0af89e
Branches
Tags
1 merge request!1ajout des tests unitaire dans optinum
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
# This file is machine-generated - editing it directly is not advised
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[Bzip2_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "3663bfffede2ef41358b6fc2e1d8a6d50b3c3904"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.6+2"
[[ColorSchemes]]
deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random", "StaticArrays"]
git-tree-sha1 = "7a15e3690529fd1042f0ab954dff7445b1efc8a5"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.9.0"
[[ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "27eb374570946a02aa184ef5b403dabaa7380693"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.10.4"
[[Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "InteractiveUtils", "Reexport"]
git-tree-sha1 = "1e9bba7984e78aa8cdeea7f9f7cc984ad4e4b1c7"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.2"
[[Contour]]
deps = ["StaticArrays"]
git-tree-sha1 = "0b17db36e7e03f8437e0d1f55aea3e4a60c74353"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.5.3"
[[DataAPI]]
git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.3.0"
[[DataStructures]]
deps = ["InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "be680f1ad03c0a03796aa3fda5a2180df7f83b46"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.17.18"
[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
[[DocStringExtensions]]
deps = ["LibGit2", "Markdown", "Pkg", "Test"]
git-tree-sha1 = "c5714d9bcdba66389612dc4c47ed827c64112997"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.2"
[[Documenter]]
deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "395fa1554c69735802bba37d9e7d9586fd44326c"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.24.11"
[[FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "c82bef6fc01e30d500f588cd01d29bdd44f1924e"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.3.0"
[[FFMPEG_jll]]
deps = ["Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "LAME_jll", "LibVPX_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "0fa07f43e5609ea54848b82b4bb330b250e9645b"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.1.0+3"
[[FixedPointNumbers]]
git-tree-sha1 = "8fb797c37a3b7ced4327a05ac4ca0dd6a4f1ba92"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.1"
[[FreeType2_jll]]
deps = ["Bzip2_jll", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "7d900f32a3788d4eacac2bfa3bf5c770179c8afd"
uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.10.1+2"
[[FriBidi_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "2f56bee16bd0151de7b6a1eeea2ced190a2ad8d4"
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.5+3"
[[GR]]
deps = ["Base64", "DelimitedFiles", "HTTP", "JSON", "LinearAlgebra", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"]
git-tree-sha1 = "247adbd2b33c0c4b42efa20d1e807acf6312145f"
uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
version = "0.50.1"
[[GeometryTypes]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "StaticArrays"]
git-tree-sha1 = "34bfa994967e893ab2f17b864eec221b3521ba4d"
uuid = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
version = "0.8.3"
[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"]
git-tree-sha1 = "ec87d5e2acbe1693789efbbe14f5ea7525758f71"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.8.15"
[[IniFile]]
deps = ["Test"]
git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.0"
[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
[[JSON]]
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"
[[LAME_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "221cc8998b9060677448cbb6375f00032554c4fd"
uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d"
version = "3.100.0+1"
[[LibGit2]]
deps = ["Printf"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
[[LibVPX_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "e3549ca9bf35feb9d9d954f4c6a9032e92f46e7c"
uuid = "dd192d2f-8180-539f-9fb4-cc70b1dcf69a"
version = "1.8.1+1"
[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"]
git-tree-sha1 = "426a6978b03a97ceb7ead77775a1da066343ec6e"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.0.2"
[[MbedTLS_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "c83f5a1d038f034ad0549f9ee4d5fac3fb429e33"
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.16.0+2"
[[Measures]]
git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f"
uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
version = "0.3.1"
[[Missings]]
deps = ["DataAPI"]
git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5"
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
version = "0.4.3"
[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
[[NaNMath]]
git-tree-sha1 = "928b8ca9b2791081dc71a51c55347c27c618760f"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.3"
[[Ogg_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "59cf7a95bf5ac39feac80b796e0f39f9d69dc887"
uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051"
version = "1.3.4+0"
[[OpenSSL_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "d2a6f25262d568b5a7e454cf7ff5066a79d16c7d"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "1.1.1+2"
[[Opus_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "002c18f222a542907e16c83c64a1338992da7e2c"
uuid = "91d4177d-7536-5919-b921-800302f37372"
version = "1.3.1+1"
[[OrderedCollections]]
git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.2.0"
[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "eb3e09940c0d7ae01b01d9291ebad7b081c844d3"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.5"
[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
[[PlotThemes]]
deps = ["PlotUtils", "Requires", "Statistics"]
git-tree-sha1 = "c6f5ea535551b3b16835134697f0c65d06c94b91"
uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
version = "2.0.0"
[[PlotUtils]]
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
git-tree-sha1 = "e18e0e51ff07bf92bb7e06dcb9c082a4e125e20c"
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
version = "1.0.5"
[[Plots]]
deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryTypes", "JSON", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"]
git-tree-sha1 = "70908194bb636437f181683625925505fd1664a8"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
version = "1.4.1"
[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
[[RecipesBase]]
git-tree-sha1 = "54f8ceb165a0f6d083f0d12cb4996f5367c6edbc"
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
version = "1.0.1"
[[RecipesPipeline]]
deps = ["Dates", "PlotUtils", "RecipesBase"]
git-tree-sha1 = "9477d23b9ded11153622d8619d0c20c4626a4ac8"
uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c"
version = "0.1.10"
[[Reexport]]
deps = ["Pkg"]
git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "0.2.0"
[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "d37400976e98018ee840e0ca4f9d20baa231dc6b"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.0.1"
[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
[[Showoff]]
deps = ["Dates"]
git-tree-sha1 = "e032c9df551fb23c9f98ae1064de074111b7bc39"
uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
version = "0.3.1"
[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
[[SortingAlgorithms]]
deps = ["DataStructures", "Random", "Test"]
git-tree-sha1 = "03f5898c9959f8115e30bc7226ada7d0df554ddd"
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
version = "0.3.1"
[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
[[StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "5c06c0aeb81bef54aed4b3f446847905eb6cbda0"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "0.12.3"
[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[[StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics"]
git-tree-sha1 = "a6102b1f364befdb05746f386b67c6b7e3262c45"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.33.0"
[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[[TestOptinum]]
deps = ["Markdown", "Test"]
git-tree-sha1 = "0f55172039cb2a8d64c8e001a040a7b53209ac67"
repo-rev = "master"
repo-url = "https://github.com/mathn7/TestOptinum"
uuid = "a6016688-b6f6-4950-8384-ab0954b6af15"
version = "0.1.0"
[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[Zlib_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "a2e0d558f6031002e380a90613b199e37a8565bf"
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.11+10"
[[libass_jll]]
deps = ["Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "Libdl", "Pkg", "Zlib_jll"]
git-tree-sha1 = "027a304b2a90de84f690949a21f94e5ae0f92c73"
uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0"
version = "0.14.0+2"
[[libfdk_aac_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "480c7ed04f68ea3edd4c757f5db5b6a0a4e0bd99"
uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280"
version = "0.1.6+2"
[[libvorbis_jll]]
deps = ["Libdl", "Ogg_jll", "Pkg"]
git-tree-sha1 = "6a66f65b5275dfa799036c8a3a26616a0a271c4a"
uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a"
version = "1.3.6+4"
[[x264_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "d89346fe63a6465a9f44e958ac0e3d366af90b74"
uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a"
version = "2019.5.25+2"
[[x265_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "61324ad346b00a6e541896b94201c9426591e43a"
uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76"
version = "3.0.0+1"
name = "Optinum"
uuid = "289cfbba-6966-46b0-8dde-953cd55d6e8f"
authors = ["relmo <rachid.elmontassir@etu.enseeiht.fr>"]
version = "0.1.0"
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestOptinum = "a6016688-b6f6-4950-8384-ab0954b6af15"
# Optinum - Méthodes numériques pour les problèmes d’optimisation # Optinum - Méthodes numériques pour les problèmes d’optimisation
## Rendu ## Rendu
Le projet est à rendre sous Moodle *le vendredi 17 décembre à 18h00*. Vous rendrez un fichier compressé `nom du binome .tgz` qui déarchivez contiendra un répertoire `votre nom` qui lui-même contiendra vos répertoire Optinum et TestOptinum. Votre notebook doit se trouver dans le sous répertoire `Optinum/src`. Le projet est à rendre sous Moodle *le vendredi 17 décembre à 18h00*. Vous rendrez un fichier compressé `votre nom.tgz` qui déarchivez contiendra un répertoire `votre nom` qui lui-même contiendra vos répertoire Optinum et TestOptinum. Votre notebook doit se trouver dans le sous répertoire `Optinum/src`.
## Instalation de julia et jupyter notebook sur vos machines ## Instalation de julia et jupyter notebook sur vos machines
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
# Intégration numérique avec Julia, une introduction # Intégration numérique avec Julia, une introduction
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
## Introduction ## Introduction
Il nous faut tout d'abord importer les bons packages de Julia Il nous faut tout d'abord importer les bons packages de Julia
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
# import Pkg; Pkg.add("DifferentialEquations") # import Pkg; Pkg.add("DifferentialEquations")
# Pkg.add("Plots") # Pkg.add("Plots")
# import Pkg; Pkg.add("ODEInterfaceDiffEq") # import Pkg; Pkg.add("ODEInterfaceDiffEq")
using DifferentialEquations using DifferentialEquations
using Plots using Plots
``` ```
   
%% Output
┌ Info: Precompiling DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa]
└ @ Base loading.jl:1342
ERROR: LoadError: ArgumentError: Package DataStructures does not have Compat in its dependencies:
- If you have DataStructures checked out for development and have
added Compat as a dependency but haven't updated your primary
environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with DataStructures
Stacktrace:
[1] require(into::Module, mod::Symbol)
 @ Base ./loading.jl:906
[2] include
 @ ./Base.jl:386 [inlined]
[3] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
 @ Base ./loading.jl:1235
[4] top-level scope
 @ none:1
[5] eval
 @ ./boot.jl:360 [inlined]
[6] eval(x::Expr)
 @ Base.MainInclude ./client.jl:446
[7] top-level scope
 @ none:1
in expression starting at /Users/gergaud/.julia/packages/DataStructures/nBjdy/src/DataStructures.jl:1
ERROR: LoadError: Failed to precompile DataStructures [864edb3b-99cc-5e75-8d2d-829cb0a9cfe8] to /Users/gergaud/.julia/compiled/v1.6/DataStructures/jl_FUK9uh.
Stacktrace:
[1] error(s::String)
 @ Base ./error.jl:33
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IOContext{Base.PipeEndpoint}, internal_stdout::IOContext{Base.PipeEndpoint}, ignore_loaded_modules::Bool)
 @ Base ./loading.jl:1385
[3] compilecache(pkg::Base.PkgId, path::String)
 @ Base ./loading.jl:1329
[4] _require(pkg::Base.PkgId)
 @ Base ./loading.jl:1043
[5] require(uuidkey::Base.PkgId)
 @ Base ./loading.jl:936
[6] require(into::Module, mod::Symbol)
 @ Base ./loading.jl:923
[7] include
 @ ./Base.jl:386 [inlined]
[8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
 @ Base ./loading.jl:1235
[9] top-level scope
 @ none:1
[10] eval
 @ ./boot.jl:360 [inlined]
[11] eval(x::Expr)
 @ Base.MainInclude ./client.jl:446
[12] top-level scope
 @ none:1
in expression starting at /Users/gergaud/.julia/packages/StatsBase/Q76Ni/src/StatsBase.jl:1
ERROR: LoadError: Failed to precompile StatsBase [2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91] to /Users/gergaud/.julia/compiled/v1.6/StatsBase/jl_aTmMTx.
Stacktrace:
[1] error(s::String)
 @ Base ./error.jl:33
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IOContext{Base.PipeEndpoint}, internal_stdout::IOContext{Base.PipeEndpoint}, ignore_loaded_modules::Bool)
 @ Base ./loading.jl:1385
[3] compilecache(pkg::Base.PkgId, path::String)
 @ Base ./loading.jl:1329
[4] _require(pkg::Base.PkgId)
 @ Base ./loading.jl:1043
[5] require(uuidkey::Base.PkgId)
 @ Base ./loading.jl:936
[6] require(into::Module, mod::Symbol)
 @ Base ./loading.jl:923
[7] include
 @ ./Base.jl:386 [inlined]
[8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
 @ Base ./loading.jl:1235
[9] top-level scope
 @ none:1
[10] eval
 @ ./boot.jl:360 [inlined]
[11] eval(x::Expr)
 @ Base.MainInclude ./client.jl:446
[12] top-level scope
 @ none:1
in expression starting at /Users/gergaud/.julia/packages/Distributions/1cqVu/src/Distributions.jl:1
ERROR: LoadError: Failed to precompile Distributions [31c24e10-a181-5473-b8eb-7969acd0382f] to /Users/gergaud/.julia/compiled/v1.6/Distributions/jl_tmg8Kh.
Stacktrace:
[1] error(s::String)
 @ Base ./error.jl:33
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IOContext{Base.PipeEndpoint}, internal_stdout::IOContext{Base.PipeEndpoint}, ignore_loaded_modules::Bool)
 @ Base ./loading.jl:1385
[3] compilecache(pkg::Base.PkgId, path::String)
 @ Base ./loading.jl:1329
[4] _require(pkg::Base.PkgId)
 @ Base ./loading.jl:1043
[5] require(uuidkey::Base.PkgId)
 @ Base ./loading.jl:936
[6] require(into::Module, mod::Symbol)
 @ Base ./loading.jl:923
[7] include
 @ ./Base.jl:386 [inlined]
[8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::String)
 @ Base ./loading.jl:1235
[9] top-level scope
 @ none:1
[10] eval
 @ ./boot.jl:360 [inlined]
[11] eval(x::Expr)
 @ Base.MainInclude ./client.jl:446
[12] top-level scope
 @ none:1
in expression starting at /Users/gergaud/.julia/packages/DiffEqBase/b1nST/src/DiffEqBase.jl:1
ERROR: LoadError: Failed to precompile DiffEqBase [2b5f629d-d688-5b77-993f-72d75c75574e] to /Users/gergaud/.julia/compiled/v1.6/DiffEqBase/jl_L6uKwc.
Stacktrace:
[1] error(s::String)
 @ Base ./error.jl:33
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IOContext{Base.PipeEndpoint}, internal_stdout::IOContext{Base.PipeEndpoint}, ignore_loaded_modules::Bool)
 @ Base ./loading.jl:1385
[3] compilecache(pkg::Base.PkgId, path::String)
 @ Base ./loading.jl:1329
[4] _require(pkg::Base.PkgId)
 @ Base ./loading.jl:1043
[5] require(uuidkey::Base.PkgId)
 @ Base ./loading.jl:936
[6] require(into::Module, mod::Symbol)
 @ Base ./loading.jl:923
[7] include
 @ ./Base.jl:386 [inlined]
[8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
 @ Base ./loading.jl:1235
[9] top-level scope
 @ none:1
[10] eval
 @ ./boot.jl:360 [inlined]
[11] eval(x::Expr)
 @ Base.MainInclude ./client.jl:446
[12] top-level scope
 @ none:1
in expression starting at /Users/gergaud/.julia/packages/DifferentialEquations/7WPQg/src/DifferentialEquations.jl:1
Failed to precompile DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa] to /Users/gergaud/.julia/compiled/v1.6/DifferentialEquations/jl_g1kMjp.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IJulia.IJuliaStdio{Base.PipeEndpoint}, internal_stdout::IJulia.IJuliaStdio{Base.PipeEndpoint}, ignore_loaded_modules::Bool)
@ Base ./loading.jl:1385
[3] compilecache(pkg::Base.PkgId, path::String)
@ Base ./loading.jl:1329
[4] _require(pkg::Base.PkgId)
@ Base ./loading.jl:1043
[5] require(uuidkey::Base.PkgId)
@ Base ./loading.jl:936
[6] require(into::Module, mod::Symbol)
@ Base ./loading.jl:923
[7] eval
@ ./boot.jl:360 [inlined]
[8] 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:
   
## Pendule simple ## Pendule simple
### Introduction ### Introduction
On s'intéresse ici au pendule simple. Les principes physiques de la mécanique classique donnent comme équation qui régit l'évolution du mouvement On s'intéresse ici au pendule simple. Les principes physiques de la mécanique classique donnent comme équation qui régit l'évolution du mouvement
$$ ml^2\ddot{\alpha}(t)+mlg\sin(\alpha(t)) + k\dot{\alpha}(t)=0,$$ $$ ml^2\ddot{\alpha}(t)+mlg\sin(\alpha(t)) + k\dot{\alpha}(t)=0,$$
où $\ddot{\alpha}(t)$ désigne la dérivée seconde de l'angle $\alpha$ par rapport au temps $t$. où $\ddot{\alpha}(t)$ désigne la dérivée seconde de l'angle $\alpha$ par rapport au temps $t$.
   
On prend ici comme variable d'état qui décrit le système $x(t)=(x_1(t),x_2(t))=(\alpha(t), \dot{\alpha}(t))$. Le système différentiel du premier ordre que l'on obtient s'écrit alors On prend ici comme variable d'état qui décrit le système $x(t)=(x_1(t),x_2(t))=(\alpha(t), \dot{\alpha}(t))$. Le système différentiel du premier ordre que l'on obtient s'écrit alors
$$ $$
\left\{\begin{array}{l} \left\{\begin{array}{l}
\dot{x}_1(t) = x_2(t)\\ \dot{x}_1(t) = x_2(t)\\
\dot{x}_2(t) = -\frac{g}{l}\sin(x_1(t))-kx_2(t)\\ \dot{x}_2(t) = -\frac{g}{l}\sin(x_1(t))-kx_2(t)\\
x_1(0) = x_{0,1}=\alpha_0\\ x_1(0) = x_{0,1}=\alpha_0\\
x_2(0) = x_{0,2}=\dot{\alpha}_0 x_2(0) = x_{0,2}=\dot{\alpha}_0
\end{array}\right. \end{array}\right.
$$ $$
### Cas où la fonction second membre renvoie xpoint ### Cas où la fonction second membre renvoie xpoint
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
function pendule(x,p,t) function pendule(x,p,t)
# second member of the IVP # second member of the IVP
# x : state # x : state
# real(2) # real(2)
# p : parameter vector # p : parameter vector
# t : time, variable not use here # t : time, variable not use here
# real # real
# Output # Output
# xpoint : vector of velocity # xpoint : vector of velocity
# same as x # same as x
g = p[1]; l = p[2]; k = p[3] g = p[1]; l = p[2]; k = p[3]
xpoint = similar(x) xpoint = similar(x)
xpoint[1] = x[2] xpoint[1] = x[2]
xpoint[2] = -(g/l)*sin(x[1]) - k*x[2] xpoint[2] = -(g/l)*sin(x[1]) - k*x[2]
return xpoint return xpoint
end end
``` ```
   
%% Output %% Output
   
pendule (generic function with 1 method) pendule (generic function with 1 method)
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
# Main # Main
# #
g = 9.81; l = 10; k = 0; g = 9.81; l = 10; k = 0;
p = [g,l,k] # constantes p = [g,l,k] # constantes
theta0 = pi/3 theta0 = pi/3
t0 = 0. t0 = 0.
tf = 3*pi*sqrt(l/g)*(1 + theta0^2/16 + theta0^4/3072) # 2*approximation de la période tf = 3*pi*sqrt(l/g)*(1 + theta0^2/16 + theta0^4/3072) # 2*approximation de la période
tspan = (t0,tf) # instant initial et terminal tspan = (t0,tf) # instant initial et terminal
x0 = [theta0,0] # état initial x0 = [theta0,0] # état initial
prob = ODEProblem(pendule,x0,tspan,p) # défini le problème en Julia prob = ODEProblem(pendule,x0,tspan,p) # défini le problème en Julia
sol = solve(prob) # réalise l'intégration numérique sol = solve(prob) # réalise l'intégration numérique
plot(sol, label = ["x_1(t)" "x_2(t)"]) plot(sol, label = ["x_1(t)" "x_2(t)"])
``` ```
   
%% Output %% Output
   
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
### Cas où xpoint est le premier argument modifié de la fonction second membre ### Cas où xpoint est le premier argument modifié de la fonction second membre
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
function pendule1!(xpoint,x,p,t) function pendule1!(xpoint,x,p,t)
# second member of the IVP # second member of the IVP
# x : state # x : state
# real(2) # real(2)
# p : parameter vector # p : parameter vector
# t : time, variable not use here # t : time, variable not use here
# real # real
# Output # Output
# xpoint : vector of velocity # xpoint : vector of velocity
# same as x # same as x
g = p[1]; l = p[2]; k = p[3] g = p[1]; l = p[2]; k = p[3]
xpoint = similar(x) xpoint = similar(x)
xpoint[1] = x[2] xpoint[1] = x[2]
xpoint[2] = -(g/l)*sin(x[1]) - k*x[2] xpoint[2] = -(g/l)*sin(x[1]) - k*x[2]
return nothing return nothing
end end
``` ```
   
%% Output %% Output
   
pendule1! (generic function with 1 method) pendule1! (generic function with 1 method)
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
# Main # Main
# #
g = 9.81; l = 10; k = 0; g = 9.81; l = 10; k = 0;
p = [g,l,k] # constantes p = [g,l,k] # constantes
theta0 = pi/3 theta0 = pi/3
t0 = 0. t0 = 0.
tf = 3*pi*sqrt(l/g)*(1 + theta0^2/16 + theta0^4/3072) # 2*approximation de la période tf = 3*pi*sqrt(l/g)*(1 + theta0^2/16 + theta0^4/3072) # 2*approximation de la période
tspan = (t0,tf) # instant initial et terminal tspan = (t0,tf) # instant initial et terminal
x0 = [theta0,0] # état initial x0 = [theta0,0] # état initial
prob = ODEProblem(pendule1!,x0,tspan,p) # défini le problème en Julia prob = ODEProblem(pendule1!,x0,tspan,p) # défini le problème en Julia
sol = solve(prob) # réalise l'intégration numérique sol = solve(prob) # réalise l'intégration numérique
plot(sol, label = ["x_1(t)" "x_2(t)"]) plot(sol, label = ["x_1(t)" "x_2(t)"])
``` ```
   
%% Output %% Output
   
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
L'instruction `xpoint = similar(x)` **crée une variable locale xpoint** et on a perdu le paramètre formel `xpoint`. L'instruction `xpoint = similar(x)` **crée une variable locale xpoint** et on a perdu le paramètre formel `xpoint`.
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
function pendule2!(xpoint,x,p,t) function pendule2!(xpoint,x,p,t)
# second member of the IVP # second member of the IVP
# x : state # x : state
# real(2) # real(2)
# p : parameter vector # p : parameter vector
# t : time, variable not use here # t : time, variable not use here
# real # real
# Output # Output
# xpoint : vector of velocity # xpoint : vector of velocity
# same as x # same as x
g = p[1]; l = p[2]; k = p[3] g = p[1]; l = p[2]; k = p[3]
xpoint[1] = x[2] xpoint[1] = x[2]
xpoint[2] = -(g/l)*sin(x[1]) - k*x[2] xpoint[2] = -(g/l)*sin(x[1]) - k*x[2]
return nothing return nothing
end end
``` ```
   
%% Output %% Output
   
pendule2! (generic function with 1 method) pendule2! (generic function with 1 method)
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
# Main # Main
# #
g = 9.81; l = 10; k = 0.; g = 9.81; l = 10; k = 0.;
p = [g,l,k] # constantes p = [g,l,k] # constantes
theta0 = pi/3 theta0 = pi/3
t0 = 0. t0 = 0.
tf = 3*pi*sqrt(l/g)*(1 + theta0^2/16 + theta0^4/3072) # 2*approximation de la période tf = 3*pi*sqrt(l/g)*(1 + theta0^2/16 + theta0^4/3072) # 2*approximation de la période
tspan = (t0,tf) # instant initial et terminal tspan = (t0,tf) # instant initial et terminal
x0 = [theta0,0] # état initial x0 = [theta0,0] # état initial
prob = ODEProblem(pendule2!,x0,tspan,p) # défini le problème en Julia prob = ODEProblem(pendule2!,x0,tspan,p) # défini le problème en Julia
sol = solve(prob) # réalise l'intégration numérique sol = solve(prob) # réalise l'intégration numérique
plot(sol, label = ["x_1(t)" "x_2(t)"]) plot(sol, label = ["x_1(t)" "x_2(t)"])
``` ```
   
%% Output %% Output
   
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
## Diagrammes de phases ## Diagrammes de phases
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
# Main # Main
# #
g = 9.81; l = 10; k = 0.; # si k = 0.15 donc on a un amortissement g = 9.81; l = 10; k = 0.; # si k = 0.15 donc on a un amortissement
p = [g l k] p = [g l k]
plot() plot()
for theta0 in 0:(2*pi)/10:2*pi for theta0 in 0:(2*pi)/10:2*pi
theta0_princ = theta0 theta0_princ = theta0
tf = 3*pi*sqrt(l/g)*(1 + theta0_princ^2/16 + theta0_princ^4/3072) # 2*approximation of the period tf = 3*pi*sqrt(l/g)*(1 + theta0_princ^2/16 + theta0_princ^4/3072) # 2*approximation of the period
tspan = (0.0,tf) tspan = (0.0,tf)
x0 = [theta0 0] x0 = [theta0 0]
prob = ODEProblem(pendule,x0,tspan,p) prob = ODEProblem(pendule,x0,tspan,p)
sol = solve(prob) sol = solve(prob)
plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth
end end
theta0 = pi-10*eps() theta0 = pi-10*eps()
x0 = [theta0 0] x0 = [theta0 0]
tf = 70 # problem for tf=50 1/4 of the period! tf = 70 # problem for tf=50 1/4 of the period!
tspan = (0.0,tf) tspan = (0.0,tf)
prob = ODEProblem(pendule,x0,tspan,p) prob = ODEProblem(pendule,x0,tspan,p)
sol = solve(prob) sol = solve(prob)
plot!(sol,vars=(1,2), xlims = (-2*pi,4*pi), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth plot!(sol,vars=(1,2), xlims = (-2*pi,4*pi), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth
   
theta0 = pi+10*eps() theta0 = pi+10*eps()
x0 = [theta0 0] x0 = [theta0 0]
tf = 70 tf = 70
tspan = (0.0,tf) tspan = (0.0,tf)
prob = ODEProblem(pendule,x0,tspan,p) prob = ODEProblem(pendule,x0,tspan,p)
sol = solve(prob) sol = solve(prob)
plot!(sol,vars=(1,2), xlims = (-2*pi,4*pi), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth plot!(sol,vars=(1,2), xlims = (-2*pi,4*pi), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth
   
# circulation case # circulation case
for thetapoint0 in 0:0.2:2 for thetapoint0 in 0:0.2:2
tf = 10 tf = 10
tspan = (0.,tf) tspan = (0.,tf)
x0 = [-pi thetapoint0] # thetapoint0 > 0 so theta increases from -pi to ... x0 = [-pi thetapoint0] # thetapoint0 > 0 so theta increases from -pi to ...
prob = ODEProblem(pendule,x0,tspan,p) prob = ODEProblem(pendule,x0,tspan,p)
sol = solve(prob) sol = solve(prob)
plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth
end end
for thetapoint0 in -2:0.2:0 for thetapoint0 in -2:0.2:0
tf = 10 tf = 10
tspan = (0.,tf) tspan = (0.,tf)
x0 = [3*pi thetapoint0] # thetapoint0 < 0 so theta decreases from 3pi to ... x0 = [3*pi thetapoint0] # thetapoint0 < 0 so theta decreases from 3pi to ...
prob = ODEProblem(pendule,x0,tspan,p) prob = ODEProblem(pendule,x0,tspan,p)
sol = solve(prob) sol = solve(prob)
plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) # lw = linewidth
end end
plot!([-pi 0 pi 2*pi 3*pi], [0 0 0 0 0], seriestype=:scatter) plot!([-pi 0 pi 2*pi 3*pi], [0 0 0 0 0], seriestype=:scatter)
plot!(xlims = (-pi,3*pi)) plot!(xlims = (-pi,3*pi))
``` ```
   
%% Output %% Output
   
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
## Modèle de Van der Pol ## Modèle de Van der Pol
### Exemple de cycle limite ### Exemple de cycle limite
L'équation différentielle considérée est l'équation de Van der Pol L'équation différentielle considérée est l'équation de Van der Pol
$$(IVP)\left\{\begin{array}{l} $$(IVP)\left\{\begin{array}{l}
\dot{y}_1(t)=y_2(t)\\ \dot{y}_1(t)=y_2(t)\\
\dot{y}_2(t)=(1-y_1^2(t))y_2(t)-y_1(t)\\ \dot{y}_2(t)=(1-y_1^2(t))y_2(t)-y_1(t)\\
y_1(0)=2.00861986087484313650940188\\ y_1(0)=2.00861986087484313650940188\\
y_2(0)=0 y_2(0)=0
\end{array}\right. \end{array}\right.
$$ $$
$t_f=T=6.6632868593231301896996820305$ $t_f=T=6.6632868593231301896996820305$
   
   
La solution de ce problème de Cauchy est périodique de période $T$. La solution de ce problème de Cauchy est périodique de période $T$.
   
Résoudre et de visualiser la solution pour les points de départ : Résoudre et de visualiser la solution pour les points de départ :
- x0 = [2.00861986087484313650940188,0] - x0 = [2.00861986087484313650940188,0]
- [x01 , 0] pour x01 in -2:0.4:0 - [x01 , 0] pour x01 in -2:0.4:0
- [0 , x02] pour x02 in 2:1:4 - [0 , x02] pour x02 in 2:1:4
   
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
function vdp(x,p,t) function vdp(x,p,t)
# Van der Pol model # Van der Pol model
# second member of the IVP # second member of the IVP
# x : state # x : state
# real(2) # real(2)
# p : parameter vector # p : parameter vector
# t : time, variable not use here # t : time, variable not use here
# real # real
# Output # Output
# xpoint : vector of velocity # xpoint : vector of velocity
# same as x # same as x
# To complete # To complete
# xpoint = similar(x) # xpoint = similar(x)
# xpoint[1] = x[2] # xpoint[1] = x[2]
# xpoint[2] = (1-x[1]^2)*x[2] - x[1] # xpoint[2] = (1-x[1]^2)*x[2] - x[1]
xpoint = [x[2] , (1-x[1]^2)*x[2] - x[1]] xpoint = [x[2] , (1-x[1]^2)*x[2] - x[1]]
return xpoint return xpoint
end end
``` ```
   
%% Output %% Output
   
vdp (generic function with 1 method) vdp (generic function with 1 method)
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
# Main # Main
# #
tf = 6.6632868593231301896996820305 tf = 6.6632868593231301896996820305
tspan = (0.0, tf) tspan = (0.0, tf)
x0 = [2.00861986087484313650940188,0] x0 = [2.00861986087484313650940188,0]
mu = 1 mu = 1
p = [mu] p = [mu]
t0 = 0.; t0 = 0.;
tspan = (t0,tf) tspan = (t0,tf)
println("x0 = $x0, p = $p, tspan = $tspan") println("x0 = $x0, p = $p, tspan = $tspan")
prob = ODEProblem(vdp,x0,tspan,p) prob = ODEProblem(vdp,x0,tspan,p)
sol = solve(prob) sol = solve(prob)
plot(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) plot(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false)
for x01 in -2:0.4:0 #4.5:4.5 for x01 in -2:0.4:0 #4.5:4.5
x0 = [x01,0] x0 = [x01,0]
prob = ODEProblem(vdp,x0,tspan,p) prob = ODEProblem(vdp,x0,tspan,p)
sol = solve(prob)#,force_dtmin=true)# sol = solve(prob)#,force_dtmin=true)#
plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false)
end end
for x02 in 2:1:4 for x02 in 2:1:4
x0 = [0.,x02] x0 = [0.,x02]
prob = ODEProblem(vdp,x0,tspan,p) prob = ODEProblem(vdp,x0,tspan,p)
sol = solve(prob)#solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8) sol = solve(prob)#solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8)
plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false) plot!(sol,vars=(1,2), xlabel = "x_1", ylabel = "x_2", legend = false)
end end
plot!([0], [0], seriestype=:scatter) # point visualisation plot!([0], [0], seriestype=:scatter) # point visualisation
plot!(xlims = (-2.5,5)) plot!(xlims = (-2.5,5))
   
   
``` ```
   
%% Output %% Output
   
x0 = [2.0086198608748433, 0.0], p = [1], tspan = (0.0, 6.66328685932313) x0 = [2.0086198608748433, 0.0], p = [1], tspan = (0.0, 6.66328685932313)
   
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
La solution périodique est ici ce qu'on appelle un **cycle limite** La solution périodique est ici ce qu'on appelle un **cycle limite**
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
# Modèle de Lorentz # Modèle de Lorentz
## Chaos ## Chaos
$$(IVP)\left\{\begin{array}{l} $$(IVP)\left\{\begin{array}{l}
\dot{x}_1(t)=-\sigma x_1(t)+\sigma x_2(t)\\ \dot{x}_1(t)=-\sigma x_1(t)+\sigma x_2(t)\\
\dot{x}_2(t)=-x_1(t)x_3(t)+rx_1(t)-x_2(t)\\ \dot{x}_2(t)=-x_1(t)x_3(t)+rx_1(t)-x_2(t)\\
\dot{x}_3(t)=x_1(t)x_2(t)-bx_3(t)\\ \dot{x}_3(t)=x_1(t)x_2(t)-bx_3(t)\\
x_1(0)=-8\\ x_1(0)=-8\\
x_2(0)=8\\ x_2(0)=8\\
x_3(0)=r-1 x_3(0)=r-1
\end{array}\right. \end{array}\right.
$$ $$
avec $\sigma=10, r=28, b=8/3$. avec $\sigma=10, r=28, b=8/3$.
   
Calculer et visualisé la solution de ce problème Calculer et visualisé la solution de ce problème
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
function lorentz(x,p,t) function lorentz(x,p,t)
# Lorentz model # Lorentz model
# second member of the IVP # second member of the IVP
# x : state # x : state
# real(3) # real(3)
# p : parameter vector # p : parameter vector
# t : time, variable not use here # t : time, variable not use here
# real # real
# Output # Output
# xpoint : vector of velocity # xpoint : vector of velocity
# same as x # same as x
# To complete # To complete
sigma = p[1]; rho = p[2]; beta = p[3]; sigma = p[1]; rho = p[2]; beta = p[3];
xpoint = similar(x) xpoint = similar(x)
xpoint[1] = sigma*(x[2]-x[1]) xpoint[1] = sigma*(x[2]-x[1])
xpoint[2] = x[1]*(rho-x[3]) - x[2] xpoint[2] = x[1]*(rho-x[3]) - x[2]
xpoint[3] = x[1]*x[2] - beta*x[3] xpoint[3] = x[1]*x[2] - beta*x[3]
return xpoint return xpoint
end end
``` ```
   
%% Output %% Output
   
lorentz (generic function with 1 method) lorentz (generic function with 1 method)
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
# test de la fonction lorent! # test de la fonction lorent!
sigma = 10.; rho = 28.; beta = 8/3; sigma = 10.; rho = 28.; beta = 8/3;
p = [sigma rho beta] p = [sigma rho beta]
#x0 = [1.1,0.0,0.0] #x0 = [1.1,0.0,0.0]
x0 = [-8, 8, rho-1] x0 = [-8, 8, rho-1]
xpoint = x0 xpoint = x0
xpoint = lorentz(x0,p,0) xpoint = lorentz(x0,p,0)
println("xpoint = $xpoint") println("xpoint = $xpoint")
``` ```
   
%% Output %% Output
   
xpoint = [160.0, -16.0, -136.0] xpoint = [160.0, -16.0, -136.0]
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
# Main # Main
# #
x0 = [-8, 8, rho-1] x0 = [-8, 8, rho-1]
tspan = (0.0,100.0) tspan = (0.0,100.0)
prob = ODEProblem(lorentz,x0,tspan,p) prob = ODEProblem(lorentz,x0,tspan,p)
sol = solve(prob) sol = solve(prob)
plot(sol,vars=(1,2,3), xlabel = "x_1", ylabel = "x_2", zlabel = "x_3", legend = false) plot(sol,vars=(1,2,3), xlabel = "x_1", ylabel = "x_2", zlabel = "x_3", legend = false)
plot!([x0[1]], [x0[2]], [x0[3]], seriestype=:scatter) # point visualisation plot!([x0[1]], [x0[2]], [x0[3]], seriestype=:scatter) # point visualisation
#annotate!([x0[1],x0[2],x0[3],text(". Point de départ", 10,:left)]) #annotate!([x0[1],x0[2],x0[3],text(". Point de départ", 10,:left)])
``` ```
   
%% Output %% Output
   
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
p1 = plot(sol,vars=(0,1),ylabel = "x_1(t)", legend = false) p1 = plot(sol,vars=(0,1),ylabel = "x_1(t)", legend = false)
p2 = plot(sol,vars=(0,2),ylabel = "x_2(t)", legend = false) p2 = plot(sol,vars=(0,2),ylabel = "x_2(t)", legend = false)
p3 = plot(sol,vars=(0,3),xlabel = "t", ylabel = "x_3(t)", legend = false) p3 = plot(sol,vars=(0,3),xlabel = "t", ylabel = "x_3(t)", legend = false)
plot(p1,p2,p3,layout=(3,1))#,legend=false) plot(p1,p2,p3,layout=(3,1))#,legend=false)
``` ```
   
%% Output %% Output
   
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
## Attention à bien utiliser les codes ## Attention à bien utiliser les codes
Nous allons ici résoudre le problème à valeur initiale Nous allons ici résoudre le problème à valeur initiale
$$(IVP)\left\{\begin{array}{l} $$(IVP)\left\{\begin{array}{l}
\dot{x}_1(t)=x_1(t)+x_2(t)+\sin t\\ \dot{x}_1(t)=x_1(t)+x_2(t)+\sin t\\
\dot{x}_2(t)=-x_1(t)+3x_2(t)\\ \dot{x}_2(t)=-x_1(t)+3x_2(t)\\
x_1(0)=-9/25\\ x_1(0)=-9/25\\
x_2(0)=-4/25, x_2(0)=-4/25,
\end{array}\right. \end{array}\right.
$$ $$
dont la solution est dont la solution est
\begin{align*} \begin{align*}
x_1(t)&= (-1/25)(13\sin t+9\cos t)\\ x_1(t)&= (-1/25)(13\sin t+9\cos t)\\
x_2(t)&= (-1/25)(3\sin t+4\cos t). x_2(t)&= (-1/25)(3\sin t+4\cos t).
\end{align*} \end{align*}
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
function exemple1(x,p,t) function exemple1(x,p,t)
# second member of the IVP # second member of the IVP
# Input # Input
# x : state # x : state
# real(2) # real(2)
# p : parameter vector # p : parameter vector
# t : time # t : time
# real # real
# Output # Output
# xpoint : vector of velocity # xpoint : vector of velocity
# same as x # same as x
xpoint = similar(x) # xpoint est un objet de même type que x xpoint = similar(x) # xpoint est un objet de même type que x
xpoint[1] = x[1] + x[2] + sin(t) xpoint[1] = x[1] + x[2] + sin(t)
xpoint[2] = -x[1] + 3*x[2] xpoint[2] = -x[1] + 3*x[2]
# xpoint = [x[1]+x[2]+sin(t), -x[1] + 3*x[2]] # xpoint = [x[1]+x[2]+sin(t), -x[1] + 3*x[2]]
return xpoint return xpoint
end end
p = [] p = []
t0 = 0.; tf = 8 t0 = 0.; tf = 8
tspan = (t0,tf) tspan = (t0,tf)
x0 = [-9/25 , -4/25] x0 = [-9/25 , -4/25]
prob = ODEProblem(exemple1,x0,tspan,p) # défini le problème en Julia prob = ODEProblem(exemple1,x0,tspan,p) # défini le problème en Julia
sol = solve(prob, DP5()) # réalise l'intégration numérique sol = solve(prob, DP5()) # réalise l'intégration numérique
# avec ode45 de matlab # avec ode45 de matlab
p1 = plot(sol, label = ["x_1(t)" "x_2(t)"], title = "ode45 de Matlab") #, lw = 0.5) # lw = linewidth p1 = plot(sol, label = ["x_1(t)" "x_2(t)"], title = "ode45 de Matlab") #, lw = 0.5) # lw = linewidth
sol = solve(prob, DP5(), reltol = 1.e-6, abstol = 1.e-9) sol = solve(prob, DP5(), reltol = 1.e-6, abstol = 1.e-9)
p2 = plot(sol, label = ["x_1(t)" "x_2(t)"], title = "reltol=1.e-6, abstol=1.e-9") #, lw = 0.5) p2 = plot(sol, label = ["x_1(t)" "x_2(t)"], title = "reltol=1.e-6, abstol=1.e-9") #, lw = 0.5)
sol = solve(prob, DP5(), reltol = 1.e-10, abstol = 1.e-15) sol = solve(prob, DP5(), reltol = 1.e-10, abstol = 1.e-15)
p3 = plot(sol, label = ["x_1(t)" "x_2(t)"], title = "reltol=1.e-10, abstol=1.e-16") #, lw = 0.5) p3 = plot(sol, label = ["x_1(t)" "x_2(t)"], title = "reltol=1.e-10, abstol=1.e-16") #, lw = 0.5)
T = t0:(tf-t0)/100:tf T = t0:(tf-t0)/100:tf
sinT = map(sin,T) # opération vectorielle sinT = map(sin,T) # opération vectorielle
cosT = map(cos,T) cosT = map(cos,T)
p4 = plot(T,[(-1/25)*(13*sinT+9*cosT) (-1/25)*(3*sinT+4*cosT)], label = ["x_1(t)" "x_2(t)"], xlabel = "t", title = "Solution exacte") p4 = plot(T,[(-1/25)*(13*sinT+9*cosT) (-1/25)*(3*sinT+4*cosT)], label = ["x_1(t)" "x_2(t)"], xlabel = "t", title = "Solution exacte")
plot(p1,p2,p3,p4) plot(p1,p2,p3,p4)
``` ```
   
%% Output %% Output
   
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` julia ``` julia
``` ```
...@@ -49,11 +49,9 @@ function Algorithme_De_Newton(f::Function,gradf::Function,hessf::Function,x0,opt ...@@ -49,11 +49,9 @@ function Algorithme_De_Newton(f::Function,gradf::Function,hessf::Function,x0,opt
Tol_abs = options[2] Tol_abs = options[2]
Tol_rel = options[3] Tol_rel = options[3]
end end
xmin = x0
n = length(x0) f_min = f(x0)
xmin = zeros(n)
f_min = 0
flag = 0 flag = 0
nb_iters = 0 nb_iters = 0
return xmin,f_min,flag,nb_iters return xmin,f_min,flag,nb_iters
end end
%% 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> Année 2020-2021 - 2e année département Sciences du Numérique </h1> <h1> Année 2020-2021 - 2e année département Sciences du Numérique </h1>
<h1> Noms: </h1> <h1> Noms: </h1>
<h1> Prénoms: </h1> <h1> Prénoms: </h1>
</center> </center>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Algorithme de Newton # Algorithme de Newton
## Implémentation ## Implémentation
1. Coder l’algorithme de Newton local tel que décrit dans la section *Algorithme de Newton* (fichier `Algorithme_De_Newton.jl`) 1. Coder l’algorithme de Newton local tel que décrit dans la section *Algorithme de Newton* (fichier `Algorithme_De_Newton.jl`)
2. Tester l’algorithme sur les fonctions $f_{1}$ , $f_{2}$ avec les points initiaux $x_{011}$ , $x_{012}$ (pour $f_{1}$ ) et $x_{021}$ , $x_{022}$ , $x_{023}$ (pour $f_{2}$ ) donnés en Annexe A. 2. Tester l’algorithme sur les fonctions $f_{1}$ , $f_{2}$ avec les points initiaux $x_{011}$ , $x_{012}$ (pour $f_{1}$ ) et $x_{021}$ , $x_{022}$ , $x_{023}$ (pour $f_{2}$ ) donnés en Annexe A.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` julia ``` julia
using Pkg using Pkg
Pkg.status() Pkg.status()
Pkg.add("DifferentialEquations")
``` ```
%% Output %% Output
Project Optinum v0.1.0  Status `~/.julia/environments/v1.6/Project.toml`
Status `~/ENS/optinum/TP/Optinum/Project.toml`  [336ed68f] CSV v0.9.10
 [e30172f5] Documenter v0.24.11  [a93c6f00] DataFrames v1.2.2
 [28b8d3ca] GR v0.50.1  [0c46a032] DifferentialEquations v6.20.0
 [91a5bcdd] Plots v1.4.1  [7073ff75] IJulia v1.23.2
 [a6016688] TestOptinum v0.1.0 #master (https://github.com/mathn7/TestOptinum)  [91a5bcdd] Plots v1.23.6
 [37e2e46d] LinearAlgebra 
 [d6f4376e] Markdown 
 [8dfed614] Test 
 Updating registry at `~/.julia/registries/General`
┌ Warning: Some registries failed to update:
│ — `~/.julia/registries/General` — registry dirty
└ @ Pkg.Types /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Pkg/src/Types.jl:1122
 Resolving package versions...
 Installed ArrayLayouts ────────── v0.3.4
 Installed DifferentialEquations ─ v6.14.0
 Installed SymbolicUtils ───────── v0.3.4
 Installed NLsolve ─────────────── v4.4.0
 Installed BandedMatrices ──────── v0.15.12
 Installed StochasticDiffEq ────── v6.23.1
 Installed AbstractAlgebra ─────── v0.9.2
 Installed LightGraphs ─────────── v1.3.3
 Installed CEnum ───────────────── v0.4.1
 Installed Distances ───────────── v0.9.0
 Installed DiffEqNoiseProcess ──── v4.2.0
 Installed ModelingToolkit ─────── v3.10.2
 Installed Distributions ───────── v0.23.4
 Updating `~/ENS/optinum/TP/Optinum/Project.toml`
 [0c46a032] + DifferentialEquations v6.14.0
 Updating `~/ENS/optinum/TP/Optinum/Manifest.toml`
 [c3fe647b] + AbstractAlgebra v0.9.2
 [1520ce14] + AbstractTrees v0.3.3
 [79e6a3ab] + Adapt v1.1.0
 [ec485272] + ArnoldiMethod v0.0.4
 [7d9fca2a] + Arpack v0.4.0
 [68821587] + Arpack_jll v3.5.0+3
 [4fba245c] + ArrayInterface v2.8.7
 [4c555306] + ArrayLayouts v0.3.4
 [aae01518] + BandedMatrices v0.15.12
 [764a87c0] + BoundaryValueDiffEq v2.5.0
 [fa961155] + CEnum v0.4.1
 [a603d957] + CanonicalTraits v0.2.1
 [d360d2e6] + ChainRulesCore v0.8.0
 [861a8166] + Combinatorics v1.0.2
 [bbf7d656] + CommonSubexpressions v0.2.0
 [34da2185] + Compat v3.12.0
 [e66e0078] + CompilerSupportLibraries_jll v0.3.3+0
 [88cd18e8] + ConsoleProgressMonitor v0.1.2
 [187b0558] + ConstructionBase v1.0.0
 [adafc99b] + CpuId v0.2.2
 [bcd4f6db] + DelayDiffEq v5.24.1
 [2b5f629d] + DiffEqBase v6.38.4
 [459566f4] + DiffEqCallbacks v2.13.3
 [5a0ffddc] + DiffEqFinancial v2.3.0
 [c894b116] + DiffEqJump v6.9.1
 [77a26b50] + DiffEqNoiseProcess v4.2.0
 [055956cb] + DiffEqPhysics v3.2.0
 [163ba53b] + DiffResults v1.0.2
 [b552c78f] + DiffRules v1.0.1
 [0c46a032] + DifferentialEquations v6.14.0
 [c619ae07] + DimensionalPlotRecipes v1.2.0
 [b4f34e82] + Distances v0.9.0
 [31c24e10] + Distributions v0.23.4
 [d4d017d3] + ExponentialUtilities v1.6.0
 [1a297f60] + FillArrays v0.8.10
 [6a86dc24] + FiniteDiff v2.3.2
 [59287772] + Formatting v0.4.1
 [f6369f11] + ForwardDiff v0.10.10
 [069b7b12] + FunctionWrappers v1.1.1
 [6b9d7cbe] + GeneralizedGenerated v0.2.4
 [01680d73] + GenericSVD v0.3.0
 [d25df0c9] + Inflate v0.1.2
 [42fd0dbc] + IterativeSolvers v0.8.4
 [82899510] + IteratorInterfaceExtensions v1.0.0
 [b14d175d] + JuliaVariables v0.2.0
 [b964fa9f] + LaTeXStrings v1.1.0
 [2ee39098] + LabelledArrays v1.2.2
 [23fbe1c1] + Latexify v0.13.5
 [1d6d02ad] + LeftChildRightSiblingTrees v0.1.2
 [093fc24a] + LightGraphs v1.3.3
 [d3d80556] + LineSearches v7.0.1
 [e6f89c97] + LoggingExtras v0.4.1
 [bdcacae8] + LoopVectorization v0.8.5
 [d00139f3] + METIS_jll v5.1.0+4
 [d8e11817] + MLStyle v0.3.1
 [1914dd2f] + MacroTools v0.5.5
 [961ee093] + ModelingToolkit v3.10.2
 [46d2c3a1] + MuladdMacro v0.2.2
 [f9640e96] + MultiScaleArrays v1.8.1
 [d41bc354] + NLSolversBase v7.6.1
 [2774e3e8] + NLsolve v4.4.0
 [71a1bf82] + NameResolution v0.1.3
 [6fe1bfb0] + OffsetArrays v1.0.4
 [4536629a] + OpenBLAS_jll v0.3.9+4
 [efe28fd5] + OpenSpecFun_jll v0.5.3+3
 [1dea7af3] + OrdinaryDiffEq v5.41.0
 [90014a1f] + PDMats v0.9.12
 [65888b18] + ParameterizedFunctions v5.3.0
 [d96e819e] + Parameters v0.12.1
 [e409e4f3] + PoissonRandom v0.4.0
 [8162dcfd] + PrettyPrint v0.1.0
 [33c8b6b6] + ProgressLogging v0.1.2
 [92933f4c] + ProgressMeter v1.3.1
 [1fd47b50] + QuadGK v2.3.1
 [e6cf234a] + RandomNumbers v1.4.0
 [731186ca] + RecursiveArrayTools v2.4.4
 [f2c3362d] + RecursiveFactorization v0.1.2
 [ae5879a3] + ResettableStacks v1.0.0
 [79098fc4] + Rmath v0.6.1
 [f50d1b31] + Rmath_jll v0.2.2+1
 [f2b01f46] + Roots v1.0.2
 [21efa798] + SIMDPirates v0.8.7
 [476501e8] + SLEEFPirates v0.5.1
 [1bc83da4] + SafeTestsets v0.0.1
 [699a6c99] + SimpleTraits v0.9.2
 [47a9eef4] + SparseDiffTools v1.8.0
 [276daf66] + SpecialFunctions v0.10.3
 [4c63d2b9] + StatsFuns v0.9.5
 [9672c7b4] + SteadyStateDiffEq v1.5.1
 [789caeaf] + StochasticDiffEq v6.23.1
 [bea87d4a] + SuiteSparse_jll v5.4.0+8
 [c3572dad] + Sundials v4.2.3
 [fb77eaff] + Sundials_jll v5.2.0+0
 [d1185830] + SymbolicUtils v0.3.4
 [3783bdb8] + TableTraits v1.0.0
 [5d786b92] + TerminalLoggers v0.1.1
 [a759f4b9] + TimerOutputs v0.5.6
 [a2a6695c] + TreeViews v0.3.0
 [3a884ed6] + UnPack v1.0.1
 [1986cc42] + Unitful v1.2.1
 [3d5dd08c] + VectorizationBase v0.12.6
 [19fa3120] + VertexSafeGraphs v0.1.2
 [700de1a5] + ZygoteRules v0.2.0
 [1a1011a3] + SharedArrays 
 [4607b0f0] + SuiteSparse 
%% 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 %% Output
------------------------------------------------------------------------- -------------------------------------------------------------------------
Résultats de : Newton appliqué à f0 au point initial -1.5707963267948966: Résultats de : Newton appliqué à f0 au point initial -1.5707963267948966:
* xsol = [0.0] * xsol = [0.0]
* f(xsol) = 0 * f(xsol) = 0
* nb_iters = 0 * nb_iters = 0
* flag = 0 * flag = 0
* sol_exacte : -1.5707963267948966 * sol_exacte : -1.5707963267948966
------------------------------------------------------------------------- -------------------------------------------------------------------------
Résultats de : Newton appliqué à f0 au point initial -1.0707963267948966: Résultats de : Newton appliqué à f0 au point initial -1.0707963267948966:
* xsol = [0.0] * xsol = [0.0]
* f(xsol) = 0 * f(xsol) = 0
* nb_iters = 0 * nb_iters = 0
* flag = 0 * flag = 0
* sol_exacte : -1.5707963267948966 * sol_exacte : -1.5707963267948966
------------------------------------------------------------------------- -------------------------------------------------------------------------
Résultats de : Newton appliqué à f0 au point initial 1.5707963267948966: Résultats de : Newton appliqué à f0 au point initial 1.5707963267948966:
* xsol = [0.0] * xsol = [0.0]
* f(xsol) = 0 * f(xsol) = 0
* nb_iters = 0 * nb_iters = 0
* flag = 0 * flag = 0
* sol_exacte : -1.5707963267948966 * sol_exacte : -1.5707963267948966
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Interprétation ## Interprétation
Justifier Justifier
1. les résultats obtenus pour l'exemple $f_0$ ci-dessus; 1. les résultats obtenus pour l'exemple $f_0$ ci-dessus;
2. que l’algorithme implémenté converge en une itération pour $f_{1}$; 2. que l’algorithme implémenté converge en une itération pour $f_{1}$;
3. que l’algorithme puisse ne pas converger pour $f_{2}$ avec certains points initiaux. 3. que l’algorithme puisse ne pas converger pour $f_{2}$ avec certains points initiaux.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Vos réponses? ## Vos réponses?
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Régions de confiance avec pas de cauchy # Régions de confiance avec pas de cauchy
## Implémentation ## Implémentation
1. Coder l'algorithme du pas de Cauchy d’un sous-problème de 1. Coder l'algorithme du pas de Cauchy d’un sous-problème de
régions de confiance (fichier `Pas_De_Cauchy.jl`). Tester sur les quadratiques proposées en Annexe B. régions de confiance (fichier `Pas_De_Cauchy.jl`). Tester sur les quadratiques proposées en Annexe B.
2. Coder l'algorithme de régions de confiance (fichier `Regions_De_Confiance.jl`). Tester sur les problèmes de l’Annexe A. 2. Coder l'algorithme de régions de confiance (fichier `Regions_De_Confiance.jl`). Tester sur les problèmes de l’Annexe A.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` julia ``` julia
# Vos tests # Vos tests
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Interprétation ## Interprétation
1. Quelle relation lie la fonction test $f_1$ et son modèle de Taylor à l’ordre 2 ? Comparer alors les performances de Newton et RC-Pas de Cauchy sur cette fonction. 1. Quelle relation lie la fonction test $f_1$ et son modèle de Taylor à l’ordre 2 ? Comparer alors les performances de Newton et RC-Pas de Cauchy sur cette fonction.
2. Le rayon initial de la région de confiance est un paramètre important dans l’analyse 2. Le rayon initial de la région de confiance est un paramètre important dans l’analyse
de la performance de l’algorithme. Sur quel(s) autre(s) paramètre(s) peut-on jouer de la performance de l’algorithme. Sur quel(s) autre(s) paramètre(s) peut-on jouer
pour essayer d’améliorer cette performance ? Étudier l’influence d’au moins deux de pour essayer d’améliorer cette performance ? Étudier l’influence d’au moins deux de
ces paramètres. ces paramètres.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Vos réponses? ## Vos réponses?
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Régions de confiance avec gradient conjugué tronqué # Régions de confiance avec gradient conjugué tronqué
## Implémentation ## Implémentation
1. Implémenter l’algorithme du Gradient Conjugué Tronqué, en se basant sur le cours (fichier `Gradient_Conjugue_Tronque.jl`). 1. Implémenter l’algorithme du Gradient Conjugué Tronqué, en se basant sur le cours (fichier `Gradient_Conjugue_Tronque.jl`).
On validera les résultats sur les fonctions de l’Annexe C. On validera les résultats sur les fonctions de l’Annexe C.
2. Intégrer finalement l’algorithme du Gradient Conjugué Tronqué dans le code de 2. Intégrer finalement l’algorithme du Gradient Conjugué Tronqué dans le code de
régions de confiance, et appliquer ce code pour résoudre les exemples proposés en régions de confiance, et appliquer ce code pour résoudre les exemples proposés en
Annexe A. Annexe A.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` julia ``` julia
# Vos tests # Vos tests
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Interprétation ## Interprétation
1. Comparer la décroissance obtenue avec celle du pas de Cauchy, en retournant, dans 1. Comparer la décroissance obtenue avec celle du pas de Cauchy, en retournant, dans
un premier temps le dernier itéré admissible à courbure positive (c’est à dire, que si un premier temps le dernier itéré admissible à courbure positive (c’est à dire, que si
l’une ou l’autre des deux conditions (b) ou (d) sont rencontrées dans l’algorithme 3, l’une ou l’autre des deux conditions (b) ou (d) sont rencontrées dans l’algorithme 3,
alors on ne calcule pas ``σ_{j}`` et on retourne le dernier itéré ``s_{j}`` directement). alors on ne calcule pas ``σ_{j}`` et on retourne le dernier itéré ``s_{j}`` directement).
2. Comparer la décroissance obtenue avec celle du pas de Cauchy, en imposant la sortie 2. Comparer la décroissance obtenue avec celle du pas de Cauchy, en imposant la sortie
dans l’algorithme 3 au bout d’une itération seulement. Que remarquez vous ? dans l’algorithme 3 au bout d’une itération seulement. Que remarquez vous ?
3. Comparer la décroissance obtenue avec celle du pas de Cauchy dans le cas général. 3. Comparer la décroissance obtenue avec celle du pas de Cauchy dans le cas général.
4. Quels sont les avantages et inconvénients des deux approches ? 4. Quels sont les avantages et inconvénients des deux approches ?
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Vos réponses? ## Vos réponses?
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Lagrangien augmenté # Lagrangien augmenté
## Implémentation ## Implémentation
1.Choisir des critères d’arrêt pour la convergence de l'algorithme. 1.Choisir des critères d’arrêt pour la convergence de l'algorithme.
2.Implémenter l'algorithme du lagrangien augmenté, en utilisant les différentes méthodes 2.Implémenter l'algorithme du lagrangien augmenté, en utilisant les différentes méthodes
qui ont été vues en première partie pour la résolution de la suite de problémes sans qui ont été vues en première partie pour la résolution de la suite de problémes sans
contraintes (fichier `Lagrangien_Augmente.jl`) contraintes (fichier `Lagrangien_Augmente.jl`)
3.Tester les différentes variantes sur les problèmes en Annexe D. 3.Tester les différentes variantes sur les problèmes en Annexe D.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` julia ``` julia
# Vos tests # Vos tests
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Interprétation ## Interprétation
1.Commenter les résultats obtenus, en étudiant notamment les valeurs de $\lambda_k$ et $\mu_k$. 1.Commenter les résultats obtenus, en étudiant notamment les valeurs de $\lambda_k$ et $\mu_k$.
2.Étudier l'influence du paramètre $\tau$ dans la performance de l'algorithme. 2.Étudier l'influence du paramètre $\tau$ dans la performance de l'algorithme.
3.**Supplémentaire** : 3.**Supplémentaire** :
Que proposez-vous comme méthode pour la résolution des problèmes avec Que proposez-vous comme méthode pour la résolution des problèmes avec
des contraintes à la fois d'égalité et d'inégalité ? Implémenter (si le temps le permet) des contraintes à la fois d'égalité et d'inégalité ? Implémenter (si le temps le permet)
ce nouvel algorithme ce nouvel algorithme
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Vos réponses? ## Vos réponses?
......
using Test
@doc doc"""
Cacher les traces d'appels des tests erronés ou échoués, pour les remettre, décommentez les lignes 11 et 16.
"""
function cacher_stacktrace()
Test.eval(quote
function record(ts::DefaultTestSet, t::Union{Fail, Error})
if myid() == 1
#printstyled(ts.description, ": ", color=:white) # afficher la description du testset
# ne pas afficher pour les tests interrompus
if !(t isa Error) || t.test_type != :test_interrupted
# print(t) # afficher le resultat et la solution attendu
if !isa(t, Error)
# Base.show_backtrace(stdout, scrub_backtrace(backtrace())) # afficher la trace d'appels
end
end
end
push!(ts.results, t)
t, isa(t, Error) || backtrace()
end
end)
end
"""
Ce fichier contient toutes fonctions utilisés dans les tests des algorithmes :
- L'algorithme de Newton
- Les régions de confiance
- Le Lagrangien augmenté
"""
# Les points initiaux
# pour les problèmes sans contraintes
struct Pts_sans_contraintes
x011
x012
x021
x022
x023
end
x011 = [1; 0; 0]
x012 = [10; 3; -2.2]
x021 = [-1.2; 1]
x022 = [10; 0]
x023 = [0; 1/200 + 1/10^12]
# les points initiaux utilisés dans les problèmes sans contraintes
pts1 = Pts_sans_contraintes(x011,x012,x021,x022,x023)
# pour les problèmes avec contraintes
struct Pts_avec_contraintes
x01
x02
x03
x04
end
x01 = [0; 1; 1]
x02 = [0.5; 1.25; 1]
x03 = [1; 0]
x04 = [sqrt(3)/2 ;sqrt(3)/2]
pts2 = Pts_avec_contraintes(x01,x02,x03,x04)
# Les solutions exactes
# sol_exacte_fct1 = -hess_fct1(x011)\grad_fct1(zero(similar(x011)))
sol_exacte_fct1 = [1;1;1]
sol_exacte_fct2 = [1;1]
"""
La première fonction de test
# Expression
fct1(x) = 2*(x[1]+x[2]+x[3]-3)^2 + (x[1]-x[2])^2 + (x[2]-x[3])^2
"""
fct1(x) = 2*(x[1]+x[2]+x[3]-3)^2 + (x[1]-x[2])^2 + (x[2]-x[3])^2
# la gradient de la fonction fct1
function grad_fct1(x)
y1 = 4*(x[1]+x[2]+x[3]-3) + 2*(x[1]-x[2])
y2 = 4*(x[1]+x[2]+x[3]-3) - 2*(x[1]-x[2]) +2*(x[2]-x[3])
y3 = 4*(x[1]+x[2]+x[3]-3) - 2*(x[2]-x[3])
return [y1;y2;y3]
end
# la hessienne de la fonction fct1
hess_fct1(x) = [6 2 4;2 8 2;4 2 6]
"""
La première fonction de test
# Expression
fct2(x)=100*(x[2]-x[1]^2)^2+(1-x[1])^2
"""
fct2(x)=100*(x[2]-x[1]^2)^2+(1-x[1])^2
# la gradient de la fonction fct2
grad_fct2(x)=[-400*x[1]*(x[2]-x[1]^2)-2*(1-x[1]) ; 200*(x[2]-x[1]^2)]
#la hessienne de la fonction fct2
hess_fct2(x)=[-400*(x[2]-3*x[1]^2)+2 -400*x[1];-400*x[1] 200]
# Pour les problèmes avec contraintes
# solutions
sol_fct1_augm = [0.5 ; 1.25 ; 0.5]
sol_fct2_augm = [0.9072339605110892; 0.82275545631455]
"""
La première contrainte
# Expression
contrainte1(x) = x[1]+x[3]-1
"""
contrainte1(x) = x[1]+x[3]-1
grad_contrainte1(x) = [1 ;0; 1]
hess_contrainte1(x) = [0 0 0;0 0 0;0 0 0]
"""
La deuxième contrainte
# Expression
contrainte2(x) = (x[1]^2) + (x[2]^2) -1.5
"""
contrainte2(x) = (x[1]^2) + (x[2]^2) -1.5
grad_contrainte2(x) = [2*x[1] ;2*x[2]]
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("-------------------------------------------------------------------------")
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
using Markdown using Markdown
using Test using Test
using LinearAlgebra using LinearAlgebra
using TestOptinum
using Optinum
include("../src/Algorithme_De_Newton.jl") include("../src/Algorithme_De_Newton.jl")
include("../src/Gradient_Conjugue_Tronque.jl") include("../src/Gradient_Conjugue_Tronque.jl")
include("../src/Lagrangien_Augmente.jl") include("../src/Lagrangien_Augmente.jl")
include("../src/Pas_De_Cauchy.jl") include("../src/Pas_De_Cauchy.jl")#
include("../src/Regions_De_Confiance.jl") include("../src/Regions_De_Confiance.jl")
TestOptinum.cacher_stacktrace() #include("cacher_stacktrace.jl")
#cacher_stacktrace()
affiche = false
# Tolérance pour les tests d'égalité
tol_erreur = sqrt(eps())
## ajouter les fonctions de test
include("./fonctions_de_tests.jl")
include("./tester_algo_newton.jl")
include("tester_pas_de_cauchy.jl")
#
include("tester_gct.jl")
include("tester_regions_de_confiance.jl")
include("tester_lagrangien_augmente.jl")
affiche = true
println("affiche = ",affiche) println("affiche = ",affiche)
# Tester l'ensemble des algorithmes # Tester l'ensemble des algorithmes
@testset "Test SujetOptinum" begin @testset "Test SujetOptinum" begin
......
@doc doc"""
Tester l'algorithme de Newton local
# Entrées :
* afficher : (Bool) affichage ou non des résultats de chaque test
# Les cas de test (dans l'ordre)
* fct 1 : x011,x012
* fct 2 : x021,x022
"""
function tester_algo_newton(afficher::Bool,Algorithme_De_Newton::Function)
max_iter = 100
Tol_abs = sqrt(eps())
Tol_rel = 1e-15
options = [max_iter, Tol_abs, Tol_rel]
@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
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
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
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
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
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
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)
end
@testset "solution" begin
@test 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
end
end
@doc doc"""
Tester l'algorithme du gradient conjugué tronqué
# Entrées :
* afficher : (Bool) affichage ou non des résultats de chaque test
# Les cas de test (dans l'ordre)
* la quadratique 1
* la quadratique 2
* la quadratique 3
* la quadratique 4
* la quadratique 5
* la quadratique 6
"""
function tester_gct(afficher::Bool,Gradient_Conjugue_Tronque::Function)
tol = 1e-7
max_iter = 100
# Tolérance utilisé dans les tests
tol_test = 1e-3
@testset "Gradient-CT" begin
# le cas de test 1
grad = [0 ; 0]
Hess = [7 0 ; 0 2]
delta = 1
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s [0.0 ; 0.0] atol = tol_test
# le cas de test 2 H definie positive
grad = [6 ; 2]
Hess = [7 0 ; 0 2]
delta = 0.5 # sol = pas de Cauchy
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s -delta*grad/norm(grad) atol = tol_test
delta = 1.2 # saturation à la 2ieme itération
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s [-0.8740776099190263, -0.8221850958502244] atol = tol_test
delta = 3 # sol = min global
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s -Hess\grad atol = tol_test
# le cas test 2 bis matrice avec 1 vp < 0 et 1 vp > 0
grad = [1,2]
Hess = [1 0 ; 0 -1]
delta = 1. # g^T H g < 0 première direction concave
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s -delta*grad/norm(grad) atol = tol_test
grad = [1,0]
delta = 0.5 # g^T H g > 0 sol pas de Cauchy
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s -delta*grad/norm(grad) atol = tol_test
grad = [2,1] # g^T H g > 0 sol à l'itération 2, saturation
delta = 6
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s [0.48997991959774634, 5.979959839195494] atol = tol_test
# le cas de test 3
#grad = [-2 ; 1]
#Hess = [-2 0 ; 0 10]
#delta = 10
#s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
#@test s ≈ [9.102342582478453; -4.140937032991381] atol = tol_test
# le cas de test 4
#grad = [0 ; 0]
#Hess = [-2 0 ; 0 10]
#delta = 1
#s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
#@test s ≈ [0.0 ; 0.0] atol = tol_test
# le cas de test 5
grad = [2 ; 3]
Hess = [4 6 ; 6 5]
delta = 3
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s [1.9059020876695578 ; -2.3167946029410595] atol = tol_test
# le cas de test 6
# Le pas de Cauchy conduit à un gradient nul en 1 itération
grad = [2 ; 0]
Hess = [4 0 ; 0 -15]
delta = 2
s = Gradient_Conjugue_Tronque(grad,Hess,[delta;max_iter;tol])
@test s [-0.5 ; 0.0] atol = tol_test
end
end
@doc doc"""
Tester l'algorithme du Lagrangien augmenté
# Entrées :
* affichage : (Bool) affichage ou non des résultats de chaque test
# Les cas de test (dans l'ordre)
* Newton
* fct1 : x01, x02
* fct2 : x03, x04
* gct
* fct1 : x01, x02
* fct2 : x03, x04
* Cauchy
* fct1 : x01, x02
* fct2 : x03, x04
"""
function tester_lagrangien_augmente(afficher::Bool,Lagrangien_Augmente::Function)
# initialisation des paramètres
lambda0 = 2
mu0 = 10
tho = 2
epsilon = 1e-8
tol = 1e-5
max_iters = 1000
options = [epsilon, tol, max_iters, lambda0, mu0, tho]
# La tolérance utilisée dans les tests
tol_erreur = 1e-4
# Les trois algorithmes d'optimisations sans contraintes utlisés
algos = ["newton", "gct", "cauchy"]
@testset "Lagrangien augmenté " begin
@testset "Avec $algo" for algo in algos
# le cas de test 1
xmin,fxmin,flag,nbiters = Lagrangien_Augmente(algo,fct1,contrainte1,grad_fct1,hess_fct1,grad_contrainte1,
hess_contrainte1,pts2.x01,options)
if (afficher)
afficher_resultats("Lagrangien augmenté avec "*algo,"fonction 1","x01",xmin,fxmin,flag,sol_fct1_augm,nbiters)
end
@test isapprox(xmin,sol_fct1_augm ,atol=tol_erreur)
# le cas de test 2
xmin ,fxmin,flag,nbiters = Lagrangien_Augmente(algo,fct1,contrainte1,grad_fct1,hess_fct1,grad_contrainte1,
hess_contrainte1,pts2.x02,options)
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
# le cas de test 3
xmin,fxmin,flag,nbiters = Lagrangien_Augmente(algo,fct2,contrainte2,grad_fct2,hess_fct2,grad_contrainte2,
hess_contrainte2,pts2.x03,options)
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
# le cas de test 4
xmin ,fxmin,flag,nbiters = Lagrangien_Augmente(algo,fct2,contrainte2,grad_fct2,hess_fct2,grad_contrainte2,
hess_contrainte2,pts2.x04,options)
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
end
end
end
@doc doc"""
Tester l'algorithme de pas de Cauchy
# Entrées :
* afficher : (Bool) affichage ou non des résultats de chaque test
# Les cas de test (dans l'ordre)
* quadratique 1
* quadratique 2
* quadratique 3
"""
function tester_pas_de_cauchy(afficher::Bool,Pas_De_Cauchy::Function)
tol_erreur = 1e-6
@testset "Pas de Cauchy" begin
"# Pour la quadratique 1"
@testset "g = 0" begin
g = [0; 0]
H = [7 0 ; 0 2]
delta = 1
s, e = Pas_De_Cauchy(g,H,delta)
@test (e == 0) && (isapprox(s,[0; 0],atol=tol_erreur))
end
@testset "quad 2, non saturé" begin
g = [6; 2]
H = [7 0 ; 0 2]
delta = 1
s, e = Pas_De_Cauchy(g,H,delta)
sol = -(norm(g)^2/(g'*H*g))*g
@test (e == 1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
end
@testset "quad 2, saturé" begin
g = [6; 2]
H = [7 0 ; 0 2]
delta = 0.9
s, e = Pas_De_Cauchy(g,H,delta)
sol = -(delta/norm(g))*g
@test (e == -1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
end
@testset "quad 3, non saturé" begin
g = [-2; 1]
H = [-2 0 ; 0 10]
delta = 6
s, e = Pas_De_Cauchy(g,H,delta)
sol = -(norm(g)^2/(g'*H*g))*g
println("Cauchy 4 = ", sol)
@test (e == 1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
end
@testset "quad 3, saturé" begin
g = [-2; 1]
H = [-2 0 ; 0 10]
delta = 5
s, e = Pas_De_Cauchy(g,H,delta)
sol = -(delta/norm(g))*g
println("Cauchy 5= ", sol)
@test (e == -1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
end
@testset "quad 3, g'*H*g <0 saturé" begin
g = [3; 1]
H = [-2 0 ; 0 10]
delta = 5
s, e = Pas_De_Cauchy(g,H,delta)
sol = -(delta/norm(g))*g
println("Cauchy 6= ", sol)
@test (e == -1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
end
@testset "quad 3, g'*H*g = 0 saturé" begin
g = [1,2]
H = [2 -1 ; 4 -2]
delta = 5
s, e = Pas_De_Cauchy(g,H,delta)
sol = -(delta/norm(g))*g
println("Cauchy 6= ", sol)
@test (e == -1) && (isapprox(s,sol,atol=tol_erreur)) # sol = [-0.9230769230769234; -0.30769230769230776]
end
end
end
@doc doc"""
Tester l'algorithme des régions de confiance
# Entrées :
* affichage : (Bool) affichage ou non des résultats de chaque test
# les cas de test (dans l'ordre)
* avec Cauchy :
- fct 1 : x011,x012
- fct 2 : x021,x022,x023
* avec gct :
- fct 1 : x011,x012
- fct 2 : x021,x022,x023
"""
function tester_regions_de_confiance(afficher::Bool,Regions_De_Confiance::Function)
# La tolérance utilisée dans les tests
tol_erreur = 1e-2
# initialisation des variables de l'algorithme
gamma1 = 0.5
gamma2 = 2.00
eta1 = 0.25
eta2 = 0.75
deltaMax = 10
Tol_abs = sqrt(eps())
Tol_rel = 1e-8
maxits = 5000
delta0_1 = 2
delta0_2 = 2
options1 =[deltaMax,gamma1,gamma2,eta1,eta2,delta0_1,maxits,Tol_abs,Tol_rel]
options2 =[deltaMax,gamma1,gamma2,eta1,eta2,delta0_2,maxits,Tol_abs,Tol_rel]
# l'ensemble de tests
@testset "La méthode des RC " begin
###################################################
# les tests avec le pas de Cauchy #
###################################################
# Un premier sous-ensemble de tests
@testset "avec Cauchy " begin
# cas de test 1
x_min11, fmin11, flag11, nb_iters11 = Regions_De_Confiance("cauchy",fct1,grad_fct1,hess_fct1,pts1.x011,options1)
if (afficher)
afficher_resultats("régions de confiance avec "*"cauchy","fonction 1","x011",x_min11,fmin11, flag11,sol_exacte_fct1,nb_iters11)
end
@test isapprox(x_min11,sol_exacte_fct1 ,atol=tol_erreur)
# cas de test 2
x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("cauchy",fct1,grad_fct1,hess_fct1,pts1.x012,options1)
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
# 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
# cas de test 4
x_min22, fmin22, flag22, nb_iters22 = Regions_De_Confiance("cauchy",fct2,grad_fct2,hess_fct2,pts1.x022,options2)
println("iters = ", nb_iters22)
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
# 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
end
###################################################
# les tests avec le gradient conjugué tronqué #
###################################################
# Un deuxième sous-ensemble de tests
@testset "avec GCT " begin
# cas de test 1
x_min11, fmin11, flag11, nb_iters11= Regions_De_Confiance("gct",fct1,grad_fct1,hess_fct1,pts1.x011,options1)
if (afficher)
afficher_resultats("régions de confiance avec "*"gct","fonction 1","x011",x_min11,fmin11, flag11,sol_exacte_fct1,nb_iters11)
end
@test isapprox(x_min11,sol_exacte_fct1 ,atol=tol_erreur)
# cas de test 2
x_min12, fmin12, flag12, nb_iters12 = Regions_De_Confiance("gct",fct1,grad_fct1,hess_fct1,pts1.x012,options1)
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
# 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
# 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
# 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
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment