Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/src/manual/nonlinmpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ model = setname!(NonLinModel(f, h, Ts, nu, nx, ny; p=p_model); u=vu, x=vx, y=vy)

The output function ``\mathbf{h}`` converts the ``θ`` angle to degrees. Note that special
characters like ``θ`` can be typed in the Julia REPL or VS Code by typing `\theta` and
pressing the `<TAB>` key. Note that the parameter `p` can be of any type but use a mutable
type like a vector of you want to modify it later. A 4th order [`RungeKutta`](@ref) method
solves the differential equations by default. It is good practice to first simulate `model`
using [`sim!`](@ref) as a quick sanity check:
pressing the `<TAB>` key. The parameter `p` can be of any type but use a mutable type like a
vector of you want to modify it later. A 4th order [`RungeKutta`](@ref) method solves the
differential equations by default. It is good practice to first simulate `model` using
[`sim!`](@ref) as a quick sanity check:

```@example 1
using Plots
Expand Down
20 changes: 10 additions & 10 deletions src/model/linearization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,34 @@ julia> linmodel.A
With the nonlinear state-space model:
```math
\begin{aligned}
\mathbf{x}(k+1) &= \mathbf{f}\Big(\mathbf{x}(k), \mathbf{u}(k), \mathbf{d}(k)\Big) \\
\mathbf{y}(k) &= \mathbf{h}\Big(\mathbf{x}(k), \mathbf{d}(k)\Big)
\mathbf{x}(k+1) &= \mathbf{f}\Big(\mathbf{x}(k), \mathbf{u}(k), \mathbf{d}(k), \mathbf{p}\Big) \\
\mathbf{y}(k) &= \mathbf{h}\Big(\mathbf{x}(k), \mathbf{d}(k), \mathbf{p}\Big)
\end{aligned}
```
its linearization at the operating point ``\mathbf{x_{op}, u_{op}, d_{op}}`` is:
```math
\begin{aligned}
\mathbf{x_0}(k+1) &≈ \mathbf{A x_0}(k) + \mathbf{B_u u_0}(k) + \mathbf{B_d d_0}(k)
+ \mathbf{f(x_{op}, u_{op}, d_{op})} - \mathbf{x_{op}} \\
+ \mathbf{f(x_{op}, u_{op}, d_{op}, p)} - \mathbf{x_{op}} \\
\mathbf{y_0}(k) &≈ \mathbf{C x_0}(k) + \mathbf{D_d d_0}(k)
\end{aligned}
```
based on the deviation vectors ``\mathbf{x_0, u_0, d_0, y_0}`` introduced in [`setop!`](@ref)
documentation, and the Jacobian matrices:
```math
\begin{aligned}
\mathbf{A} &= \left. \frac{∂\mathbf{f(x, u, d)}}{∂\mathbf{x}} \right|_{\mathbf{x=x_{op},\, u=u_{op},\, d=d_{op}}} \\
\mathbf{B_u} &= \left. \frac{∂\mathbf{f(x, u, d)}}{∂\mathbf{u}} \right|_{\mathbf{x=x_{op},\, u=u_{op},\, d=d_{op}}} \\
\mathbf{B_d} &= \left. \frac{∂\mathbf{f(x, u, d)}}{∂\mathbf{d}} \right|_{\mathbf{x=x_{op},\, u=u_{op},\, d=d_{op}}} \\
\mathbf{C} &= \left. \frac{∂\mathbf{h(x, d)}}{∂\mathbf{x}} \right|_{\mathbf{x=x_{op},\, d=d_{op}}} \\
\mathbf{D_d} &= \left. \frac{∂\mathbf{h(x, d)}}{∂\mathbf{d}} \right|_{\mathbf{x=x_{op},\, d=d_{op}}}
\mathbf{A} &= \left. \frac{∂\mathbf{f(x, u, d, p)}}{∂\mathbf{x}} \right|_{\mathbf{x=x_{op},\, u=u_{op},\, d=d_{op}}} \\
\mathbf{B_u} &= \left. \frac{∂\mathbf{f(x, u, d, p)}}{∂\mathbf{u}} \right|_{\mathbf{x=x_{op},\, u=u_{op},\, d=d_{op}}} \\
\mathbf{B_d} &= \left. \frac{∂\mathbf{f(x, u, d, p)}}{∂\mathbf{d}} \right|_{\mathbf{x=x_{op},\, u=u_{op},\, d=d_{op}}} \\
\mathbf{C} &= \left. \frac{∂\mathbf{h(x, d, p)}}{∂\mathbf{x}} \right|_{\mathbf{x=x_{op},\, d=d_{op}}} \\
\mathbf{D_d} &= \left. \frac{∂\mathbf{h(x, d, p)}}{∂\mathbf{d}} \right|_{\mathbf{x=x_{op},\, d=d_{op}}}
\end{aligned}
```
Following [`setop!`](@ref) notation, we find:
```math
\begin{aligned}
\mathbf{f_{op}} &= \mathbf{f(x_{op}, u_{op}, d_{op})} \\
\mathbf{y_{op}} &= \mathbf{h(x_{op}, d_{op})}
\mathbf{f_{op}} &= \mathbf{f(x_{op}, u_{op}, d_{op}, p)} \\
\mathbf{y_{op}} &= \mathbf{h(x_{op}, d_{op}, p)}
\end{aligned}
```
Notice that ``\mathbf{f_{op} - x_{op} = 0}`` if the point is an equilibrium. The
Expand Down
8 changes: 4 additions & 4 deletions src/sim_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ The state-space description of [`LinModel`](@ref) around the operating points is
```math
\begin{aligned}
\mathbf{x_0}(k+1) &= \mathbf{A x_0}(k) + \mathbf{B_u u_0}(k) + \mathbf{B_d d_0}(k)
+ \mathbf{f_{op}} - \mathbf{x_{op}} \\
+ \mathbf{f_{op}} - \mathbf{x_{op}} \\
\mathbf{y_0}(k) &= \mathbf{C x_0}(k) + \mathbf{D_d d_0}(k)
\end{aligned}
```
and, for [`NonLinModel`](@ref):
```math
\begin{aligned}
\mathbf{x_0}(k+1) &= \mathbf{f}\Big(\mathbf{x_0}(k), \mathbf{u_0}(k), \mathbf{d_0}(k)\Big)
+ \mathbf{f_{op}} - \mathbf{x_{op}} \\
\mathbf{y_0}(k) &= \mathbf{h}\Big(\mathbf{x_0}(k), \mathbf{d_0}(k)\Big)
\mathbf{x_0}(k+1) &= \mathbf{f}\Big(\mathbf{x_0}(k), \mathbf{u_0}(k), \mathbf{d_0}(k), \mathbf{p}\Big)
+ \mathbf{f_{op}} - \mathbf{x_{op}} \\
\mathbf{y_0}(k) &= \mathbf{h}\Big(\mathbf{x_0}(k), \mathbf{d_0}(k), \mathbf{p}\Big)
\end{aligned}
```
The state `xop` and the additional `fop` operating points are frequently zero e.g.: when
Expand Down
Loading