|
| 1 | +### A Pluto.jl notebook ### |
| 2 | +# v0.20.24 |
| 3 | + |
| 4 | +using Markdown |
| 5 | +using InteractiveUtils |
| 6 | + |
| 7 | +# ╔═╡ eb792fe6-3cbe-11f1-2eca-0bd287486337 |
| 8 | +begin |
| 9 | + import Pkg |
| 10 | + # careful: this is _not_ a reproducible environment |
| 11 | + # activate the local environment |
| 12 | + Pkg.activate(".") |
| 13 | + Pkg.instantiate() |
| 14 | + using PlutoUI, PlutoLinks |
| 15 | + using CairoMakie |
| 16 | +end |
| 17 | + |
| 18 | +# ╔═╡ 869833fd-ee32-4469-ad9f-ef6489f68811 |
| 19 | +@revise using Ariadne |
| 20 | + |
| 21 | +# ╔═╡ 0aa45e3b-433b-4385-aa8c-e71e8acf725a |
| 22 | +import NonlinearSolve as NLS |
| 23 | + |
| 24 | +# ╔═╡ fa13b4ca-a809-43c4-979d-e0864874d8f6 |
| 25 | +md""" |
| 26 | +## Generalized Rosenbrock |
| 27 | +
|
| 28 | +This example is taken from Fig. 1 of: |
| 29 | +> A. Pal et al., "NonlinearSolve.jl: High-performance and robust solvers for systems |
| 30 | +> of nonlinear equations in Julia," arXiv [math.NA], 24-Mar-2024. |
| 31 | +> https://arxiv.org/abs/2403.16341 |
| 32 | +
|
| 33 | +### Problem definition |
| 34 | +
|
| 35 | +The generalized Rosenbrock function in $N$ dimensions: |
| 36 | +```math |
| 37 | +F(x)_1 = 1 - x_1, \quad F(x)_i = 10(x_i - x_{i-1}^2), \quad i = 2, \ldots, N |
| 38 | +``` |
| 39 | +""" |
| 40 | + |
| 41 | +# ╔═╡ edf5d7a1-4f17-484a-aebf-729ea149b580 |
| 42 | +function generalized_rosenbrock(x, _) |
| 43 | + return vcat( |
| 44 | + 1 - x[1], |
| 45 | + 10 .* (x[2:end] .- x[1:(end - 1)] .* x[1:(end - 1)]) |
| 46 | + ) |
| 47 | +end |
| 48 | + |
| 49 | +# ╔═╡ 078b6618-f037-44b1-9c17-4a1785170bfc |
| 50 | +N = 5 |
| 51 | + |
| 52 | +# ╔═╡ 80cde332-fbd1-49a0-bd61-944720f885fe |
| 53 | +x_start = vcat(-1.2, ones(N - 1)) |
| 54 | + |
| 55 | +# ╔═╡ 4bb5bf4b-a37b-4d02-97a6-00bece7dc9f8 |
| 56 | +md""" |
| 57 | +## using Ariadne |
| 58 | +""" |
| 59 | + |
| 60 | +# ╔═╡ 772047e4-debd-4871-a659-f91d15c3ea45 |
| 61 | +let |
| 62 | + _, stats = newton_krylov( |
| 63 | + generalized_rosenbrock, |
| 64 | + copy(x_start); |
| 65 | + algo = :gmres, |
| 66 | + linesearch! = NoLineSearch(), |
| 67 | + max_niter = 100_000 |
| 68 | + ) |
| 69 | + stats |
| 70 | +end |
| 71 | + |
| 72 | +# ╔═╡ 42a30e51-8cf7-49fa-8348-159803d4a1c3 |
| 73 | +let |
| 74 | + _, stats = newton_krylov( |
| 75 | + generalized_rosenbrock, |
| 76 | + copy(x_start); |
| 77 | + algo = :gmres, |
| 78 | + linesearch! = BacktrackingLineSearch(), |
| 79 | + max_niter = 100_000 |
| 80 | + ) |
| 81 | + stats |
| 82 | +end |
| 83 | + |
| 84 | +# ╔═╡ 4ec97f25-7af2-4138-9203-f933d8e593d9 |
| 85 | +md""" |
| 86 | +## using NonlinearSolve |
| 87 | +""" |
| 88 | + |
| 89 | +# ╔═╡ eafb63ff-857d-4cc3-84eb-19ad4dd5755a |
| 90 | +prob = NLS.NonlinearProblem(generalized_rosenbrock, x_start) |
| 91 | + |
| 92 | +# ╔═╡ 69a3e7b5-bf52-408b-bd33-80e0618b539b |
| 93 | +alg = NLS.NewtonRaphson( |
| 94 | + linesearch = missing, |
| 95 | + forcing = NLS.EisenstatWalkerForcing2(), |
| 96 | + linsolve = NLS.KrylovJL() |
| 97 | +) |
| 98 | + |
| 99 | +# ╔═╡ aa53ea6f-9d39-43ea-b130-f0c98f187958 |
| 100 | +alg2 = NLS.NewtonRaphson( |
| 101 | + linesearch = NLS.BackTracking(), |
| 102 | + forcing = NLS.EisenstatWalkerForcing2(), |
| 103 | + linsolve = NLS.KrylovJL() |
| 104 | +) |
| 105 | + |
| 106 | +# ╔═╡ 08473c35-a4f6-4115-8db5-03b13f4a2cce |
| 107 | +let |
| 108 | + sol = NLS.solve(prob, alg, reltol = 1.0e-6, abstol = 1.0e-12, verbose = false) |
| 109 | + sol.stats |
| 110 | +end |
| 111 | + |
| 112 | +# ╔═╡ 9cea0413-f915-4784-a2c0-9b041c71b649 |
| 113 | +let |
| 114 | + sol = NLS.solve(prob, alg2, reltol = 1.0e-6, abstol = 1.0e-12, verbose = false) |
| 115 | + sol.stats |
| 116 | +end |
| 117 | + |
| 118 | +# ╔═╡ Cell order: |
| 119 | +# ╠═eb792fe6-3cbe-11f1-2eca-0bd287486337 |
| 120 | +# ╠═869833fd-ee32-4469-ad9f-ef6489f68811 |
| 121 | +# ╠═0aa45e3b-433b-4385-aa8c-e71e8acf725a |
| 122 | +# ╟─fa13b4ca-a809-43c4-979d-e0864874d8f6 |
| 123 | +# ╠═edf5d7a1-4f17-484a-aebf-729ea149b580 |
| 124 | +# ╠═078b6618-f037-44b1-9c17-4a1785170bfc |
| 125 | +# ╠═80cde332-fbd1-49a0-bd61-944720f885fe |
| 126 | +# ╟─4bb5bf4b-a37b-4d02-97a6-00bece7dc9f8 |
| 127 | +# ╠═772047e4-debd-4871-a659-f91d15c3ea45 |
| 128 | +# ╠═42a30e51-8cf7-49fa-8348-159803d4a1c3 |
| 129 | +# ╟─4ec97f25-7af2-4138-9203-f933d8e593d9 |
| 130 | +# ╠═eafb63ff-857d-4cc3-84eb-19ad4dd5755a |
| 131 | +# ╠═69a3e7b5-bf52-408b-bd33-80e0618b539b |
| 132 | +# ╠═aa53ea6f-9d39-43ea-b130-f0c98f187958 |
| 133 | +# ╠═08473c35-a4f6-4115-8db5-03b13f4a2cce |
| 134 | +# ╠═9cea0413-f915-4784-a2c0-9b041c71b649 |
0 commit comments