Discrete example

Let us consider the following nonlinear difference system:

eqs={
(Subscript[x, 1])[t+1]-> (1-(Subscript[a, 1]))(Subscript[x, 1])[t]+(Subscript[a, 1])(Subscript[x, 2])[t]+(Subscript[b, 1])(Subscript[x, 1])[t]u[t],
(Subscript[x, 2])[t+1]-> (Subscript[a, 2])(Subscript[x, 1])[t]+(1-(Subscript[a, 2])(Subscript[x, 2])[t])};
vars={(Subscript[x, 1])[t],(Subscript[x, 2])[t],u[t]};
TableForm[eqs]

Let us introduce the Ore algebra A defined by

replA=ModelToReplacementRules[eqs,t];
A=OreAlgebraWithRelations[S[t],replA]

and the matrix R of ordinary differential operators, which defines the generic linearization of the above nonlinear system

MatrixForm[R=ToOrePolynomialD[eqs,vars,A]]

and the left A-module, finitely presented by R, defined by M = (A^(1×3))/(A^(1×2))R.

Let us compute the adjoint of R:

MatrixForm[Radj=Involution[R,A]]

Let us check whether or not M is torsion-free:

{Ann,Rp,Q}=Exti[Radj,A,1];
MatrixForm[Ann]

MatrixForm[Rp]

Q

Since the first matrix is identity, M is torsion-free, which proves that the generic linearization is controllable. Let us now check whether or not M is free, i.e. that generic linearization is flat.

T=LeftInverse[Q,A]

Since Q admits a left inverse T, we conclude that M is a free left A-module of rank 1. In particular, a basis of M, i.e. a flat output ξ  of the generic linearization is defined by

ApplyMatrix[T,vars]

Moreover, a parametrization of the flat system is defined by

Thread[vars->ApplyMatrix[Q,{ξ[t]}]]

From this point we will use some procedures which are not freely available (see NLControl website  http://www.nlcontrol.ioc.ee).
Let us check if the flat output of the generic linearization can be simply lifted to flat outputs of the nonlinear system. To do that we consider the one-forms corresponding to the flat outputs of the generic linearization. We try to integrate them.

BookForm[difs=ApplyMatrixD[T,{(Subscript[x, 1])[t],(Subscript[x, 2])[t],u[t]}]]

BookForm[sp=SimplifyBasis[SpanK[difs,t]]]

IntegrateOneForms[sp]

Finally we obtain that (Subscript[x, 2]) defines a flat output of the nonlinear system.