Skip to content

Commit b5184d3

Browse files
committed
added: jacobian argument to NonLinModel constructor
1 parent 478688f commit b5184d3

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/controller/linmpc.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ arguments. This controller allocates memory at each time step for the optimizati
135135
136136
# Arguments
137137
- `model::LinModel` : model used for controller predictions and state estimations.
138-
- `Hp=10+nk`: prediction horizon ``H_p``, `nk` is the number of delays in `model`.
138+
- `Hp=10+nk` : prediction horizon ``H_p``, `nk` is the number of delays in `model`.
139139
- `Hc=2` : control horizon ``H_c``.
140140
- `Mwt=fill(1.0,model.ny)` : main diagonal of ``\mathbf{M}`` weight matrix (vector).
141141
- `Nwt=fill(0.1,model.nu)` : main diagonal of ``\mathbf{N}`` weight matrix (vector).

src/model/nonlinmodel.jl

+20-10
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ struct NonLinModel{
7070
end
7171

7272
@doc raw"""
73-
NonLinModel{NT}(f::Function, h::Function, Ts, nu, nx, ny, nd=0; p=[], solver=RungeKutta(4))
74-
NonLinModel{NT}(f!::Function, h!::Function, Ts, nu, nx, ny, nd=0; p=[], solver=RungeKutta(4))
73+
NonLinModel{NT}(f::Function, h::Function, Ts, nu, nx, ny, nd=0; <keyword arguments>)
74+
NonLinModel{NT}(f!::Function, h!::Function, Ts, nu, nx, ny, nd=0; <keyword arguments>)
7575
7676
Construct a nonlinear model from state-space functions `f`/`f!` and `h`/`h!`.
7777
@@ -86,24 +86,20 @@ functions are defined as:
8686
```
8787
where ``\mathbf{x}``, ``\mathbf{y}``, ``\mathbf{u}``, ``\mathbf{d}`` and ``\mathbf{p}`` are
8888
respectively the state, output, manipulated input, measured disturbance and parameter
89-
vectors. If the dynamics is a function of the time, simply add a measured disturbance
90-
defined as ``d(t) = t``. The functions can be implemented in two possible ways:
89+
vectors. As a mather of fact, the parameter argument `p` can be any Julia objects but use a
90+
mutable type if you want to change them later e.g.: a vector. If the dynamics is a function
91+
of the time, simply add a measured disturbance defined as ``d(t) = t``. The functions can be
92+
implemented in two possible ways:
9193
9294
1. **Non-mutating functions** (out-of-place): define them as `f(x, u, d, p) -> ẋ` and
9395
`h(x, d, p) -> y`. This syntax is simple and intuitive but it allocates more memory.
9496
2. **Mutating functions** (in-place): define them as `f!(ẋ, x, u, d, p) -> nothing` and
9597
`h!(y, x, d, p) -> nothing`. This syntax reduces the allocations and potentially the
9698
computational burden as well.
9799
98-
`Ts` is the sampling time in second. `nu`, `nx`, `ny` and `nd` are the respective number of
99-
manipulated inputs, states, outputs and measured disturbances. The keyword argument `p`
100-
is the parameters of the model passed to the two functions. It can be any Julia objects but
101-
use a mutable type if you want to change them later e.g.: a vector.
102-
103100
!!! tip
104101
Replace the `d` or `p` argument with `_` in your functions if not needed (see Examples below).
105102
106-
A 4th order [`RungeKutta`](@ref) solver discretizes the differential equations by default.
107103
The rest of the documentation assumes discrete dynamics since all models end up in this
108104
form. The optional parameter `NT` explicitly set the number type of vectors (default to
109105
`Float64`).
@@ -115,6 +111,20 @@ form. The optional parameter `NT` explicitly set the number type of vectors (def
115111
116112
See also [`LinModel`](@ref).
117113
114+
# Arguments
115+
- `f::Function` or `f!`: state function.
116+
- `h::Function` or `h!`: output function.
117+
- `Ts`: sampling time of in second.
118+
- `nu`: number of manipulated inputs.
119+
- `nx`: number of states.
120+
- `ny`: number of outputs.
121+
- `nd=0`: number of measured disturbances.
122+
- `p=[]`: parameters of the model (any type).
123+
- `solver=RungeKutta(4)`: a [`DiffSolver`](@ref) object for the discretization of continuous
124+
dynamics, use `nothing` for discrete-time models (default to 4th order [`RungeKutta`](@ref)).
125+
- `jacobian=AutoForwardDiff()`: an `AbstractADType` backend when [`linearize`](@ref) is
126+
called, see [`DifferentiationInterface` doc](@extref DifferentiationInterface List).
127+
118128
# Examples
119129
```jldoctest
120130
julia> f!(ẋ, x, u, _ , p) = (ẋ .= p*x .+ u; nothing);

0 commit comments

Comments
 (0)