mlinearize

Static method of mss.

Approximate a nonlinear Simulink model by an explicit MTI (mss) model, sampled on a sparse grid.

Source: src/model/@mss/mlinearize.m

Overview

mlinearize computes an explicit multilinear time-invariant state-space (mss) approximation of a nonlinear Simulink model over a prescribed operating domain.

The nonlinear model is assumed to be of the form

δx=f(x,u),y=g(x,u), \begin{aligned} \delta x &= f(x,u), \\ y &= g(x,u), \end{aligned}

where xnxx \in \mathbb{R}^{n_x} denotes the state vector, unuu \in \mathbb{R}^{n_u} the input vector, and ynyy \in \mathbb{R}^{n_y} the output vector of Simulink model. The function returns an mss object

δx=<𝖥|𝐌(x,u)>,y=<𝖦|𝐌(x,u)>, \begin{aligned} \delta x &= \big<\mathsf{F}|\mathbf{M}(x,u) \big>, \\ y &= \big<\mathsf{G}|\mathbf{M}(x,u) \big>, \end{aligned}

where the state evolution δx\delta x is valid for both continuous-time ẋ\dot x or discrete-time xk+1x_{k+1} of the original Simulink model.

The approximation is constructed over a bounded operating region specified by lower and upper bounds for the states, inputs, and outputs.

low_bnd=[x1l,,xnxl,u1l,,unul,y1l,,ynyl], \text{low\_bnd} = \left[ x_1^{\mathrm{l}},\ldots,x_{n_x}^{\mathrm{l}}, u_1^{\mathrm{l}},\ldots,u_{n_u}^{\mathrm{l}}, y_1^{\mathrm{l}},\ldots,y_{n_y}^{\mathrm{l}} \right],

up_bnd=[x1u,,xnxu,u1u,,unuu,y1u,,ynyu], \text{up\_bnd} = \left[ x_1^{\mathrm{u}},\ldots,x_{n_x}^{\mathrm{u}}, u_1^{\mathrm{u}},\ldots,u_{n_u}^{\mathrm{u}}, y_1^{\mathrm{u}},\ldots,y_{n_y}^{\mathrm{u}} \right],

where the state variables must follow the ordering used internally by Simulink (reported by mlinearize after execution).

The function computes the coefficients of the tensors 𝖥\mathsf{F} and 𝖦\mathsf{G} following the method described in [1]. f For continuous-time models, this requires sampling and numerically integrating the model equations over a grid of operating points over the specified domain. For discrete-time models, only the former is needed.

The grid is constructed using sparse-grid interpolation [2], which is also used to efficiently perform the numerical integrations. The interpolation level, denoted by μ\mu controls both the number of grid points and the integration accuracy. The number of interpolation points grows polynomially with μ\mu as

𝒪((nx+nu)μ), \mathcal{O}\!\left((n_x+n_u)^{\mu}\right),

where nxn_x is the number of states and nun_u is the number of inputs.

Only monomials whose multilinear order is less than or equal to the specified max_order are retained. The retained monomials define the structure of the resulting multilinear model, as illustrated below.

Monomial ordering and switching behavior

Let

𝐳=[z1,z2,,zn], \mathbf{z} = [z_1, z_2, \dots, z_n]^{\top},

be a vector of variables ziz_{i}. The multilinear monomial basis

𝐦(𝐳)=i=1n[1zi] \mathbf{m}(\mathbf{z}) = \bigotimes_{i=1}^{n} \begin{bmatrix} 1 \\ z_i \end{bmatrix}

contains 2n2^n monomials, with nn \in \mathbb{N}, and \otimes is the Kronecker product. Each mk(𝐳)m_k(\mathbf{z}) its kk-th entry, i.e. one monomial.

Consider ordering the monomials generated by the recursive construction

𝐦(0)=[1],𝐦(1)=[1,z1],𝐦(2)=[1,z1,z2,z1z2],𝐦(i)=[𝐦(i1),𝐦(i1)zi],i=1,,n, \begin{aligned} \mathbf{m}^{(0)} &= [1], \\ \mathbf{m}^{(1)} &= [1, \ z_{1}], \\ \mathbf{m}^{(2)} &= [1, \ z_{1}, \ z_{2}, \ z_{1} z_{2}], \\ &\vdots \\ \mathbf{m}^{(i)} &= [\mathbf{m}^{(i-1)}, \ \mathbf{m}^{(i-1)}z_i], \quad i = 1, \dots, n, \end{aligned}

This ordering induces a structured pattern in the exponent vectors of the monomials, i.e. a vector with the order of each element in 𝐦(i)\mathbf{m}^{(i)}.

Let 𝐔{0,1}n×2n\mathbf{U} \in \{0,1\}^{n \times 2^n} be the exponent matrix, where the kk-th column 𝐔(:,k)\mathbf{U}(:,k) corresponds to the exponent vector of the monomial at position kk.

For example with n=3n=3, the monomial ordering is

𝐦(3)=[1,z1,z2,z1z2,z3,z1z3,z2z3,z1z2z3], \mathbf{m}^{(3)} = [1,\; z_1,\; z_2,\; z_1 z_2,\; z_3,\; z_1 z_3,\; z_2 z_3,\; z_1 z_2 z_3],

so that m1=1m_1 = 1, m4=z1z2m_4 = z_1 z_2 and m8=z1z2z3m_8 = z_1 z_2 z_3, and the exponent matrix is

𝐔=[010101010011001100001111]z1z2z3 \mathbf{U} = \begin{bmatrix} 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \end{bmatrix} \begin{matrix} \ \to z_{1} \\ \ \to z_{2} \\ \ \to z_{3} \end{matrix}

Here, z1z_1 switches every 20=12^0=1 monomial, z2z_2 every 21=22^1=2 monomials, and z3z_3 every 22=42^2=4 monomials.

For variable ziz_i, its exponent switches every 2i12^{i-1} monomials. The exponent matrix is computed as

𝐔(i,k)=k12i1mod2,i=1,,n,k=1,,2n. \mathbf{U}(i,k) = \left\lfloor \frac{k-1}{2^{i-1}} \right\rfloor \bmod 2, \qquad i = 1,\dots,n,\; k = 1,\dots,2^n.

Equivalently, variable ziz_i is present in blocks of length 2i12^{i-1}, alternating between absence and presence as kk increases.

Reduced set and maximum order

The multilinear order of a monomial is the number of variables it contains, which in this encoding is simply the column sum of the exponent matrix,

deg(k)=i=1n𝐔(i,k)=𝐔(:,k)1. \deg(k) = \sum_{i=1}^{n} \mathbf{U}(i,k) = \left\lVert \mathbf{U}(:,k) \right\rVert_1 .

The argument max_order =p=p keeps only the monomials up to that order,

𝒦(p)={k{1,,2n}:deg(k)p},|𝒦(p)|=j=0p(nj). \mathcal{K}(p) = \left\{\, k \in \{1,\dots,2^n\} \;:\; \deg(k) \le p \,\right\}, \qquad \bigl\lvert \mathcal{K}(p) \bigr\rvert = \sum_{j=0}^{p} \binom{n}{j}.

which leads to the reduced exponent matrix

𝐔red=𝐔(:,𝒦(p)){0,1}n×|𝒦(p)|. \mathbf{U}_{\text{red}} = \mathbf{U}\!\left(:,\mathcal{K}(p)\right) \in \{0,1\}^{\,n \times \bigl\lvert \mathcal{K}(p) \bigr\rvert}.

This is exactly the structure matrix SS of the returned mss object.

Choosing pnp \ge n retains the full basis of 2n2^n monomials (values above nn are capped to nn with a warning), so max_order trades approximation quality against model size.

Retained monomials whose coefficients all turn out to be zero are dropped afterwards by trivialReduction, so the rank of the returned model is usually smaller still.

The variables of the basis

In mlinearize the variables of the basis are the states and inputs together,

𝐳=[x1,,xnx,u1,,unu],n=nx+nu, \mathbf{z} = \left[x_1,\dots,x_{n_x},\,u_1,\dots,u_{n_u}\right]^{\top}, \qquad n = n_x + n_u,

so 𝐦(𝐳)\mathbf{m}(\mathbf{z}) is the 𝐦(x,u)\mathbf{m}(x,u) of the model above, and the exponent matrix 𝐔\mathbf{U} has one row per state and per input, in that order.

The sparse grid lives on [1,1]n[-1,1]^{n}, so each variable is first mapped onto that cube by the affine scaling built from the operating bounds,

z̃i=aizi+bi,ai=2ziuzil,bi=ziu+zilziuzil. \tilde{z}_i = a_i z_i + b_i, \qquad a_i = \frac{2}{z_i^{\text{u}} - z_i^{\text{l}}}, \qquad b_i = -\,\frac{z_i^{\text{u}} + z_i^{\text{l}}}{z_i^{\text{u}} - z_i^{\text{l}}}.

which is why the bounds may not be degenerate: ziu=zilz_i^{\text{u}} = z_i^{\text{l}} makes aia_i singular. The outputs are scaled the same way, from their own bounds.

The computation of the coefficients in 𝖥\mathsf{F} and 𝖦\mathsf{G} is done on the scaled variables 𝐳̃\tilde{\mathbf{z}}, and the coefficients are mapped back to physical units as the last step.

Requirements

External libraries

The function requires the Sparse Grids MATLAB Kit, which builds the sparse grid it samples on.

The kit is not part of the MTI-Toolbox. It is a separate package by L. Tamellini, F. Nobile and C. Piazzola, licensed BSD-2-Clause, and it is redistributed unmodified inside the toolbox — release 23.05 (“Robert”), under externalTools/sparse-grids-matlab-kit/, with its own LICENSE.txt beside it. An installed toolbox puts it on the MATLAB path, so mlinearize works with no download and no network. Running from a source checkout instead, add it to the path yourself.

It is bundled rather than fetched on your behalf, so nothing is installed silently and the capability does not depend on an external hosting link staying alive. It can still be deleted from an installed tree, which is why environmentChecker probes for it rather than assuming it.

The kit’s authors ask to be cited: the package webpage, https://sites.google.com/view/sparse-grids-kit/home, together with reference [2] below. Please do both if you publish work that used mlinearize.

Input arguments

Argument Description
model Name of the Simulink model to approximate, as a string or character vector.
low_bnd Lower bounds of the operating domain: nx+nu+nyn_x + n_u + n_y elements, ordered [x1u,,xnxu,u1u,,unuu,y1u,,ynyu][x_1^{\mathrm{u}}, \ldots, x_{n_x}^{\mathrm{u}},\, u_1^{\mathrm{u}}, \ldots, u_{n_u}^{\mathrm{u}},\, y_1^{\mathrm{u}}, \ldots, y_{n_y}^{\mathrm{u}}]. The states follow Simulink’s internal ordering, which mlinearize prints when it runs.
up_bnd Upper bounds, with the same length and ordering as low_bnd. Every entry must differ from its low_bnd counterpart: a zero-width interval makes the scaling singular and raises mlinearize:degenerateBound.
level Sparse-grid interpolation level μ\mu. The number of interpolation points grows as 𝒪((nx+nu)μ)\mathcal{O}\!\left((n_x+n_u)^{\mu}\right).
max_order Maximum multilinear order pp of the approximation. Only monomials of order p\le p are retained; values above nx+nun_x+n_u are capped to it with a warning.
tolerance (optional) Coefficient cut-off. Entries of 𝖥\mathsf{F} and 𝖦\mathsf{G} smaller than this in magnitude are set to zero before the model is assembled.

Output arguments

Output Description
msys Explicit multilinear approximation of the Simulink model, as an mss object. Continuous-time (timeStepSize = 0) or discrete-time (timeStepSize equal to the model’s sample time), matching the source model.

Syntax

msys = mss.mlinearize(model,low_bnd,up_bnd,level,max_order)
msys = mss.mlinearize(model,low_bnd,up_bnd,level,max_order,tolerance)

References

  1. Kruppa, K., Pangalos, G., and Lichtenberg, G. Multilinear approximation of nonlinear state-space models. IFAC Proceedings Volumes, 47(3):9474–9479, 2014.

  2. Piazzola, C., and Tamellini, L. The Sparse Grids Matlab kit — a Matlab implementation of sparse grids for high-dimensional function approximation and uncertainty quantification. 2023. Package webpage: https://sites.google.com/view/sparse-grids-kit/home (check it for the most up-to-date citation data).

See Also


MyToolbox Documentation | Generated automatically by CI/CD pipeline