@@ -23,7 +23,7 @@ struct NonLinModel{NT<:Real, F<:Function, H<:Function} <: SimModel{NT}
2323end
2424
2525@doc raw """
26- NonLinModel{NT}( f::Function, h::Function, Ts, nu, nx, ny, nd=0)
26+ NonLinModel{NT}(f::Function, h::Function, Ts, nu, nx, ny, nd=0)
2727 NonLinModel{NT}(f!::Function, h!::Function, Ts, nu, nx, ny, nd=0)
2828
2929Construct a nonlinear model from discrete-time state-space functions `f` and `h`.
@@ -35,14 +35,14 @@ The state update ``\mathbf{f}`` and output ``\mathbf{h}`` functions are defined
3535 \m athbf{y}(k) &= \m athbf{h}\B ig( \m athbf{x}(k), \m athbf{d}(k) \B ig)
3636 \e nd{aligned}
3737```
38- They can be specified in two forms :
38+ They can be implemented in two possible ways :
3939
4040- non-mutating functions (out-of-place): they must be defined as `f(x, u, d) -> xnext` and
41- `h(x, d) -> y`
41+ `h(x, d) -> y`. This syntax is simple and intuitive but it allocates more memory.
4242- mutating functions (in-place): they must be defined as `f!(xnext, x, u, d) -> nothing` and
4343 `h!(y, x, d) -> nothing`. This syntax reduces the allocations and potentially the
4444 computational burden as well.
45-
45+
4646`Ts` is the sampling time in second. `nu`, `nx`, `ny` and `nd` are the respective number of
4747manipulated inputs, states, outputs and measured disturbances. The optional parameter `NT`
4848explicitly specifies the number type of vectors (default to `Float64`).
@@ -51,17 +51,28 @@ explicitly specifies the number type of vectors (default to `Float64`).
5151 Replace the `d` argument with `_` if `nd = 0` (see Examples below).
5252
5353Nonlinear continuous-time state-space functions are not supported for now. In such a case,
54- manually call a differential equation solver in `f` (see [Manual](@ref man_nonlin)).
54+ manually call a differential equation solver in `f` / `f!` (see [Manual](@ref man_nonlin)).
5555
5656!!! warning
57- `f` and `h` must be pure Julia functions to use the model in [`NonLinMPC`](@ref),
57+ The two functions must be in pure Julia to use the model in [`NonLinMPC`](@ref),
5858 [`ExtendedKalmanFilter`](@ref), [`MovingHorizonEstimator`](@ref) and [`linearize`](@ref).
5959
6060See also [`LinModel`](@ref).
6161
6262# Examples
6363```jldoctest
64- julia> model = NonLinModel((x,u,_)->0.1x+u, (x,_)->2x, 10.0, 1, 1, 1)
64+ julia> model1 = NonLinModel((x,u,_)->0.1x+u, (x,_)->2x, 10.0, 1, 1, 1)
65+ Discrete-time nonlinear model with a sample time Ts = 10.0 s and:
66+ 1 manipulated inputs u
67+ 1 states x
68+ 1 outputs y
69+ 0 measured disturbances d
70+
71+ julia> f!(xnext,x,u,_) = (xnext .= 0.1x .+ u; nothing);
72+
73+ julia> h!(y,x,_) = (y .= 2x; nothing);
74+
75+ julia> model2 = NonLinModel(f!, h!, 10.0, 1, 1, 1)
6576Discrete-time nonlinear model with a sample time Ts = 10.0 s and:
6677 1 manipulated inputs u
6778 1 states x
0 commit comments