From 9f821b1c24b681e879a82f1017159fe55adb10da Mon Sep 17 00:00:00 2001 From: franckgaga Date: Fri, 25 Sep 2026 16:17:05 -0400 Subject: [PATCH 1/5] doc: minor correction in pH tutorial --- .gitignore | 1 + docs/src/manual/nonlinmpc2.md | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 57db912da..83e9e5e05 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ docs/build/ JuliaSysimage.so LocalPreferences.toml .vscode/ +.idea/ *.cov docs/Manifest.toml lcov.info diff --git a/docs/src/manual/nonlinmpc2.md b/docs/src/manual/nonlinmpc2.md index e87912306..1b4a51052 100644 --- a/docs/src/manual/nonlinmpc2.md +++ b/docs/src/manual/nonlinmpc2.md @@ -11,9 +11,9 @@ Pages = ["nonlinmpc2.md"] ## Nonlinear Model (DAE) In this example, the goal is to control the pH of a solution in a continuously stirred -tank reactor (CSTR) for neutralization. The manipulated input is the inlet flow rate of -a strong base in L/min, while the inlet flow rate of a weak acid, also in L/min, is a -measured disturbance: +tank reactor (CSTR) for neutralization. The manipulated input ``\mathbf{u}`` is the inlet +flow rate of a strong base in L/min, while the inlet flow rate of a weak acid, also in +L/min, is a measured disturbance ``\mathbf{d}``: ```math \begin{aligned} @@ -87,7 +87,7 @@ balance leads the algebraic equation: When possible, plant model should be constructed with the specialized [`NonLinModel`](@ref) for ODEs. This tutorial will still treat the system as a DAE to illustrate its API. -The pH is: +The pH is defined as: ```math \mathrm{pH} = -10 \log_{10}(a_H) ⟹ a_H = 10^{-\mathrm{pH}} @@ -195,7 +195,7 @@ plant = setname!(plant, u=vu, x=vx, y=vy, d=vd) ``` We use a [`TrapezoidalCollocation`](@ref) transcription instead of the default -[`OrthogonalCollocation`](@ref), since it is less computationnaly expensive and its accuracy +[`OrthogonalCollocation`](@ref), since it is less computationally expensive and its accuracy and stability is good enough for this case study. A simple open-loop simulation of `plant` with: @@ -288,7 +288,7 @@ disturbed by a random-walk, instead of the measured output. Among all the settin the stability on a highly nonlinear and stiff plant model like here. An exact Hessian matrix with `hessian=true` also helps for DAEs, since the dynamics are encoded in the nonlinear equality constraints. We can also bound the three estimated states to positive values since -they are concentration in mol/L: +they are concentrations in mol/L: ```@example 1 nint_ym=0; nint_u=0; # disable the default stochastic model @@ -362,4 +362,4 @@ println("Total optimization and simulation time for $N time steps: $T s") ``` Perhaps more importantly, the fast simulations ease the tuning of the estimation horizon and -covariance matrices, for iterative and trial-and-error approaches. +covariance matrices, for iterative trial-and-error approaches. From a0abed0801bbb6697eea8e3d1141291538dd78b2 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Fri, 25 Sep 2026 16:19:20 -0400 Subject: [PATCH 2/5] doc: remove redundant variable in tutorial --- docs/src/manual/nonlinmpc2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/manual/nonlinmpc2.md b/docs/src/manual/nonlinmpc2.md index 1b4a51052..0a8d98597 100644 --- a/docs/src/manual/nonlinmpc2.md +++ b/docs/src/manual/nonlinmpc2.md @@ -207,7 +207,7 @@ validates that our DAE is well-posed: ```@example 1 function simDAE(plant, N; x_0) - ny, ny, nd, nx = plant.ny, plant.ny, plant.nd, plant.nx + ny, nd, nx = plant.ny, plant.nd, plant.nx Y_data, U_data, D_data, X_data = zeros(ny, N), zeros(nu, N), zeros(nd, N), zeros(nx, N) c_Ain_0 = plant.p[1] setstate!(plant, x_0) From 722a3ffd1a4449486e3f29f8d10880106736b337 Mon Sep 17 00:00:00 2001 From: franckgaga Date: Fri, 25 Sep 2026 16:20:05 -0400 Subject: [PATCH 3/5] doc: typo correction --- docs/src/manual/nonlinmpc2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/manual/nonlinmpc2.md b/docs/src/manual/nonlinmpc2.md index 0a8d98597..65f3a7b64 100644 --- a/docs/src/manual/nonlinmpc2.md +++ b/docs/src/manual/nonlinmpc2.md @@ -200,7 +200,7 @@ and stability is good enough for this case study. A simple open-loop simulation with: 1. a bump on the base flow rate ``\mathbf{u} = q_{Bin}`` -2. a bump on the acid flow rare ``\mathbf{d} = q_{Ain}`` +2. a bump on the acid flow rate ``\mathbf{d} = q_{Ain}`` 3. a bump on the acid feed concentration ``c_{Ain}`` (an unmeasured disturbance) validates that our DAE is well-posed: From 7119033e7bfc74ad8ecafffb097c14b46d5161ff Mon Sep 17 00:00:00 2001 From: franckgaga Date: Fri, 25 Sep 2026 16:20:28 -0400 Subject: [PATCH 4/5] doc: idem --- docs/src/manual/nonlinmpc2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/manual/nonlinmpc2.md b/docs/src/manual/nonlinmpc2.md index 65f3a7b64..6782d5c16 100644 --- a/docs/src/manual/nonlinmpc2.md +++ b/docs/src/manual/nonlinmpc2.md @@ -300,7 +300,7 @@ mhe = setconstraint!(mhe, x̂min=[0, 0, 0]) ``` The state constraints are shown in round brackets next to the decision variables. There are -27 of them (3 states × 8 datapoints in the pasts + 3 arrival estimates). The arrival +27 of them (3 states × 8 datapoints in the past + 3 arrival estimates). The arrival covariance ``\mathbf{P̄}`` is constant by default for [`NonLinModelDAE`](@ref), specified by `σP_0` argument. A proper tuning of `σP_0` and `He` reduces the impact of the constant arrival approximation. We can now reproduce the last simulated scenario and see how `mhe` From 121a4dd4f586c799dd452aee4373f86cbc02b37e Mon Sep 17 00:00:00 2001 From: franckgaga Date: Fri, 25 Sep 2026 16:27:48 -0400 Subject: [PATCH 5/5] doc: minor correction ++ --- docs/src/manual/nonlinmpc2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/manual/nonlinmpc2.md b/docs/src/manual/nonlinmpc2.md index 6782d5c16..4fe053297 100644 --- a/docs/src/manual/nonlinmpc2.md +++ b/docs/src/manual/nonlinmpc2.md @@ -281,7 +281,7 @@ model = setname!(model, u=vu, x=vx̂, y=vy, d=vd) ``` Since `calc_ċ_Ain` always returns `0`, the ``c_{Ain}`` parameter is assumed to be -time-invariant. More precisely, this concentration of the acid feed is assumed to be +time-invariant. More precisely, the concentration of the acid feed is assumed to be disturbed by a random-walk, instead of the measured output. Among all the settings of the [`MovingHorizonEstimator`](@ref), a proper tuning of the covariance matrices through `σQ`, `σR` and `σP_0`, and a past horizon `He` long enough to see the main dynamics can improve