({{, (RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel])[{f,g},x,u] 
represents the model x'(t)==f(x(t),u(t)), y(t)==g(x(t),u(t)).}, {, (RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel])[sys]
gives a state-space representation corresponding to the systems model sys. }, {, (RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel])[eqns,{{(Subscript[x, 1]),(Subscript[x, 10])},…},{{(Subscript[u, 1]),(Subscript[u, 10])},…},{(Subscript[g, 1]),…},t]
gives the state-space model of the differential equations eqns with dependent variables (Subscript[x, i]), input variables (Subscript[u, i]), operating vaues (Subscript[x, i0]) and (Subscript[u, i0]), outputs (Subscript[g, i]), and independent variable t.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]) is a general representation state-space model.

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel])[{f},x,u] assumes y(t)==x(t).

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel])[{f,g},x,u,y,t] explicitly specifies the output variables y and independent variable t.

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]) allows for operating values for the states x and inputs u.

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel])[…,{{(Subscript[x, 1]),(Subscript[x, 10])},…},{{(Subscript[u, 1]),(Subscript[u, 10])},…},…] is used to indicate the operating values for the system.

In (RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel])[sys] the following systems can be converted:

In (RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel])[eqns,…] the Taylor linearization is with respect to the highest-order derivatives of (Subscript[x, i]) about the point ((Subscript[(Subscript[x, i]), 0]),(Subscript[(Subscript[u, i]), 0])) of the differential equations eqns.

In computations where the operating point (Subscript[v, i0]) is (RefLink[Automatic, paclet:ref/Automatic]), it is usually assumed to be zero.

The following option can be given:

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]) can be used in functions such as (RefLink[OutputResponse, paclet:ref/OutputResponse]) and (RefLink[SystemsModelSeriesConnect, paclet:ref/SystemsModelSeriesConnect]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (28)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Define the nonlinear system (Subscript[x, 1])'(t)==u(t)-(Subscript[x, 1])(t) (Subscript[x, 2])(t),(Subscript[x, 2])'(t)==u(t) (Subscript[x, 2])(t)+1 with output y(t)==(Subscript[x, 1])(t):

nsys=NonlinearStateSpaceModel[{{u-(Subscript[x, 1])(Subscript[x, 2]),u (Subscript[x, 2])+1},{(Subscript[x, 1])}},{(Subscript[x, 1]),(Subscript[x, 2])},u]

Plot its response to a step input with initial states at the origin:

OutputResponse[nsys,UnitStep[t],{t,0,5}];

Plot[%,{t,0,5}]

OpenersExampleSection1(Spacer1)Scope  (17)

OpenersExampleSubsection0(Spacer1)Basic Uses  (5)

A system with 2 states {(Subscript[x, 1]),(Subscript[x, 2])}, 1 input u, and 1 output:

nsys=NonlinearStateSpaceModel[{{-(Subscript[x, 2]),(Subscript[x, 1])(Subscript[x, 2])+u},{(Subscript[x, 1])}},{(Subscript[x, 1]),(Subscript[x, 2])},{u}]

Count the number of inputs and outputs:

SystemsModelDimensions[nsys]

The order of the system:

SystemsModelOrder[nsys]

A system with 2 inputs and 1 output:

NonlinearStateSpaceModel[{{-(Subscript[x, 2])+(Subscript[u, 1]),-(Subscript[x, 1]^2)+(Subscript[u, 1])+(Subscript[u, 2])},{(Subscript[x, 1])}},{(Subscript[x, 1]),(Subscript[x, 2])},{(Subscript[u, 1]),(Subscript[u, 2])}]

The response to a unit step applied to each input channel while holding the other at zero:

OutputResponse[%,UnitStep[t],{t,0,15}];

Plot[%,{t,0,15}]

A system with 1 input and 2 outputs:

nsys=NonlinearStateSpaceModel[{{(Subscript[x, 1])-(Subscript[x, 1]^2)+u,-(Subscript[x, 1])(Subscript[x, 2])+(Subscript[x, 2])u},{(Subscript[x, 1]),(Subscript[x, 1])-(Subscript[x, 2])}},{(Subscript[x, 1]),(Subscript[x, 2])},u]

A pure gain system:

gains=NonlinearStateSpaceModel[{{},{(Subscript[k, 1])(Subscript[u, 1]),(Subscript[k, 2])(Subscript[u, 2])}},{},{(Subscript[u, 1]),(Subscript[u, 2])}]

Connect the gains in series with the original system:

SystemsModelSeriesConnect[nsys,gains]

Specify operating values for the states:

NonlinearStateSpaceModel[{{(Subscript[x, 1]^2)-2 (Subscript[x, 1])+(Subscript[x, 2]),(Subscript[x, 1])(Subscript[x, 2])-(Subscript[x, 1])-(Subscript[x, 2])+1+u},{(Subscript[x, 1])}},{{(Subscript[x, 1]),1},{(Subscript[x, 2]),1}},{u}]

Obtain the (RefLink[StateSpaceModel, paclet:ref/StateSpaceModel]) using linearization about the operating values:

StateSpaceModel[%]

Explicitly specify the output and independent variables:

NonlinearStateSpaceModel[{{(Subscript[x, 2])[t],u[t]-(((Subscript[x, 2])[t])^2)},{(Subscript[x, 1])[t]}},{(Subscript[x, 1])[t],(Subscript[x, 2])[t]},{u[t]},y[t],t]

OpenersExampleSubsection1(Spacer1)System Conversions  (4)

The nonlinear representation of a (RefLink[StateSpaceModel, paclet:ref/StateSpaceModel]) with specified states:

NonlinearStateSpaceModel[(StateSpaceModelFull[0, 1, 0, 0, -2, 1, 1, 1, 0, , , ]),{(Subscript[x, 1]),(Subscript[x, 2])}]

The nonlinear state-space representation of a (RefLink[TransferFunctionModel, paclet:ref/TransferFunctionModel]) with default states:

NonlinearStateSpaceModel[(TransferFunctionModelFull[(k/(1+τ s)), , , ])]

The nonlinear representation of an (RefLink[AffineStateSpaceModel, paclet:ref/AffineStateSpaceModel]), preserving states:

NonlinearStateSpaceModel[(AffineStateSpaceModelFull[(Subscript[x, 2]), -3 (Subscript[x, 1])-4 (Subscript[x, 1]) (Subscript[x, 2]), 0, 1+(Subscript[x, 1]), (Subscript[x, 1]), 0, (Subscript[x, 1]), (Subscript[x, 2]), \[Null], \[Null], {(Subscript[\[FormalU], 1])}Automatic, ])]

The nonlinear state-space representation of a set of ODEs:

NonlinearStateSpaceModel[m x''[t]+c x'[t]+k[x[t]] x[t]==F[t],x[t],F[t],x[t],t]

OpenersExampleSubsection2(Spacer1)Model Manipulations  (2)

NonlinearStateSpaceModel[(NonlinearStateSpaceModelFull[(Subscript[x, 2]), u-Sin[(Subscript[x, 1])]-(Subscript[x, 2]), (Subscript[x, 1]), {(Subscript[x, 1]),0}, {(Subscript[x, 2]),0}, \[Null], \[Null], {{u,0}}Automatic, ]),{{(Subscript[x, 1]),κ},{(Subscript[x, 2]),0}},{{u,Sin[κ]}}]

Set new state, input, and output variables:

NonlinearStateSpaceModel[{{x+u},{x}},x,u,y]

Use state z, input v, and output w:

NonlinearStateSpaceModel[%,z,v,w]

Use (RefLink[Normal, paclet:ref/Normal]) to get the model's arguments:

Normal[(NonlinearStateSpaceModelFull[f[x[t],u[t]], g[x[t],u[t]], x[t], y[t], \[Null], {u[t]}t, ])]

OpenersExampleSubsection3(Spacer1)Operating Values  (6)

States and inputs deleted using (RefLink[SystemsModelDelete, paclet:ref/SystemsModelDelete]) are set to their operating values:

SystemsModelDelete[(NonlinearStateSpaceModelFull[(Subscript[f, 1])[(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[u, 1]),(Subscript[u, 2])], (Subscript[f, 2])[(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[u, 1]),(Subscript[u, 2])], g[(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[u, 1]),(Subscript[u, 2])], {(Subscript[x, 1]),(Subscript[x, 10])}, {(Subscript[x, 2]),(Subscript[x, 20])}, \[Null], \[Null], {{(Subscript[u, 1]),(Subscript[u, 10])},{(Subscript[u, 2]),(Subscript[u, 20])}}Automatic, ]),1,None,2]

So are the states and inputs not extracted by (RefLink[SystemsModelExtract, paclet:ref/SystemsModelExtract]):

SystemsModelExtract[(NonlinearStateSpaceModelFull[(Subscript[f, 1])[(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[u, 1]),(Subscript[u, 2])], (Subscript[f, 2])[(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[u, 1]),(Subscript[u, 2])], g[(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[u, 1]),(Subscript[u, 2])], {(Subscript[x, 1]),(Subscript[x, 10])}, {(Subscript[x, 2]),(Subscript[x, 20])}, \[Null], \[Null], {{(Subscript[u, 1]),(Subscript[u, 10])},{(Subscript[u, 2]),(Subscript[u, 20])}}Automatic, ]),2,All,1]

(RefLink[StateSpaceTransform, paclet:ref/StateSpaceTransform]) computes the operating values of the new states if the old were specified:

StateSpaceTransform[(NonlinearStateSpaceModelFull[f[x,u], g[x,u], {x,(Subscript[x, 0])}, \[Null], \[Null], {u}Automatic, ]),{{x->p[z]},{z->q[x]}}]

By default, the simulation functions assume the operating values as the initial values:

nssm=(NonlinearStateSpaceModelFull[b u+a x, c x, {x,x0}, \[Null], \[Null], {u}Automatic, ]);

(RefLink[StateResponse, paclet:ref/StateResponse]):

StateResponse[nssm,1,t]

(RefLink[OutputResponse, paclet:ref/OutputResponse]):

OutputResponse[nssm,1,t]

(RefLink[StateSpaceModel, paclet:ref/StateSpaceModel]) linearizes about all operating values:

StateSpaceModel[(NonlinearStateSpaceModelFull[f[x,u], g[x,u], {x,(Subscript[x, 0])}, \[Null], \[Null], {u}Automatic, ])]

(RefLink[AffineStateSpaceModel, paclet:ref/AffineStateSpaceModel]) only linearizes about operating values of input variables:

AffineStateSpaceModel[(NonlinearStateSpaceModelFull[f[x,u], g[x,u], {x,(Subscript[x, 0])}, \[Null], \[Null], {u}Automatic, ])]

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]) preserves operating values specified along with ODEs:

NonlinearStateSpaceModel[{x'[t]==f[x[t],u[t]]},{{x[t],(Subscript[x, 0])}},{{u[t],(Subscript[u, 0])}},g[x[t],u[t]],t]

(RefLink[FullInformationOutputRegulator, paclet:ref/FullInformationOutputRegulator]) linearizes about the operating values to compute the gains κ:

nssm=(NonlinearStateSpaceModelFull[u+w+(((-1+x))^2) x, 0, x, {x,1}, {w,-1}, \[Null], \[Null], {u}Automatic, ]);

FullInformationOutputRegulator[nssm,{"Poles",{p}}]

Compute the gains from the linearized subsystem:

StateSpaceModel[nssm];

StateFeedbackGains[SystemsModelExtract[%,All,All,1],{p}]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

Variables with operating values given as v->(Subscript[v, 0]) are taken to be {v,(Subscript[v, 0])}:

NonlinearStateSpaceModel[{{f[x,u]},{g[x,u]}},{x->(Subscript[x, 0])},{u->(Subscript[u, 0])}]

OpenersExampleSection3(Spacer1)Options  (1)

OpenersExampleSubsection4(Spacer1)SystemsModelLabels  (1)

Label the outputs and states of a system:

f={(Subscript[x, 2]),((-(Subscript[d, v]))/m)(Subscript[x, 2])+((((Subscript[F, s])+(Subscript[F, p]))Cos[(Subscript[x, 5])]-(Subscript[F, l])Sin[(Subscript[x, 5])])/m),(Subscript[x, 4]),((-(Subscript[d, v]))/m)(Subscript[x, 4])+((((Subscript[F, s])+(Subscript[F, p]))Sin[(Subscript[x, 5])]+(Subscript[F, l])Cos[(Subscript[x, 5])])/m),(Subscript[x, 6]),((-(Subscript[d, w])(Subscript[x, 5])+l((Subscript[F, s])+(Subscript[F, p])))/J)};
g={(Subscript[x, 1]),(Subscript[x, 3]),(Subscript[x, 5])};
xx={(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3]),(Subscript[x, 4]),(Subscript[x, 5]),(Subscript[x, 6])};
uu={(Subscript[F, s]),(Subscript[F, p]),(Subscript[F, l])};

NonlinearStateSpaceModel[{f,g},xx,uu,SystemsModelLabels->{Automatic,{"x","y","θ"},{"x","vx","y","vy","θ","ω"}}]

OpenersExampleSection4(Spacer1)Applications  (5)

OpenersExampleSubsection5(Spacer1)Chemical Systems  (2)

Use (RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]) to specify the equations for a two-tank system and simulate it:

Use Bernoulli's law and mass balance to derive the resulting differential equations:

eqs={(Subscript[𝒜, 1])(Subscript[𝒽, 1])'[t]==𝒬[t]-𝒸 (Subscript[𝒶, 1])(Sqrt[2ℊ (Subscript[𝒽, 1])[t]]),(Subscript[𝒜, 2])(Subscript[𝒽, 2])'[t]==𝒸 (Subscript[𝒶, 1])(Sqrt[2ℊ (Subscript[𝒽, 1])[t]])-𝒸 (Subscript[𝒶, 2])(Sqrt[2ℊ (Subscript[𝒽, 2])[t]])};

Use steady-state operating values {((𝓆^2)/(2 (𝒸^2) ℊ (Subscript[𝒶, 1]^2))),((𝓆^2)/(2 (𝒸^2) ℊ (Subscript[𝒶, 2]^2)))}:

Simplify[eqs/.{(Subscript[𝒽, 1])[t]->((𝓆^2)/(2 (𝒸^2) ℊ (Subscript[𝒶, 1]^2))),(Subscript[𝒽, 2])[t]->((𝓆^2)/(2 (𝒸^2) ℊ (Subscript[𝒶, 2]^2))),𝒬[t]->𝓆},(Subscript[𝒜, 1])>0&&(Subscript[𝒜, 2])>0&&(Subscript[𝒶, 1])>0&&(Subscript[𝒶, 2])>0&&𝒸>0&&𝓆>0]

Define the corresponding nonlinear system with input 𝒬 and output (Subscript[𝒽, 2]):

pars={𝒸->0.7,ℊ->9.8,(Subscript[𝒜, 1])->π (4^2),(Subscript[𝒶, 1])->π (0.25^2),(Subscript[𝒜, 2])->π (3^2),(Subscript[𝒶, 2])->π (0.25^2),𝓆->1};

dtank=NonlinearStateSpaceModel[eqs,{{(Subscript[𝒽, 1])[t],((𝓆^2)/(2 (𝒸^2) ℊ (Subscript[𝒶, 1]^2)))},{(Subscript[𝒽, 2])[t],((𝓆^2)/(2 (𝒸^2) ℊ (Subscript[𝒶, 2]^2)))}},{{𝒬[t],𝓆}},(Subscript[𝒽, 2])[t],t]/.pars

With a higher steady-state value for flow rate, the level in the tanks settles at a higher level:

StateResponse[dtank,1.2,{t,0,3500}];

Plot[%,{t,0,3500},PlotRange->All,PlotLegends->{"Level in tank 1", "Level in tank 2"}]

Control the level in the second tank below using a PID controller:

dtank=(NonlinearStateSpaceModelFull[((𝒬[t]-0.6084935312800112` (Sqrt[(Subscript[\[FormalX], 1])[t]]))/(16 π)), ((0.6084935312800112` (Sqrt[(Subscript[\[FormalX], 1])[t]])-0.6084935312800112` (Sqrt[(Subscript[\[FormalX], 2])[t]]))/(9 π)), (Subscript[\[FormalX], 2])[t], {(Subscript[\[FormalX], 1])[t],2.7007729084171674`}, {(Subscript[\[FormalX], 2])[t],2.7007729084171674`}, \[Null], \[Null], {{𝒬[t],1}}t, ]);

Obtain a PID controller using the linearized model and (RefLink[PIDTune, paclet:ref/PIDTune]):

tfm=TransferFunctionModel[dtank];

pid=PIDTune[tfm]

Specify a piecewise reference value for the liquid level in the second tank:

ref=({{\[Piecewise], ({{2.5, 0≤t≤2000}, {4, 2000<t≤3000}, {3.5, 3000<t≤3500}, {3, 3500<t≤4500}, {2, True}})}});

The simulations show how the closed-loop system follows the reference:

SystemsModelFeedbackConnect[SystemsModelSeriesConnect[pid,dtank]];

OutputResponse[%,ref,{t,0,7000}];

Plot[{ref,%},{t,0,7000},PlotRange->All,PlotLegends->{"Reference","Actual"},Exclusions->None]

OpenersExampleSubsection6(Spacer1)Aerospace Systems  (2)

Find the equations of motion of an aircraft's longitudinal dynamics x'==f(x,u), where the states x are {q,γ,𝒱,θ} and the inputs u are {(Subscript[δ, e]),𝒯}: (WebLink[», http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumber=703559&url=http%3A%2F%2Fieeexplore.ieee.org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D703559])

f={(ℳ/𝒥),((-(𝒯+𝒳) Sin[α]+𝒵 Cos[α]+m g Cos[γ])/(m 𝒱)),(((𝒯+𝒳) Cos[α]+𝒵 Sin[α]+m g Sin[γ])/m),q};

Here 𝒳, 𝒵, and ℳ are taken to be polynomials in α and (Subscript[δ, e]):

dim=(1/2)ρ (𝒱^2)𝒮;

𝒳=dim(((Subscript[a, 0])+(Subscript[a, 1])α+(Subscript[a, 2])(Subscript[δ, e]^2)+(Subscript[a, 3])(Subscript[δ, e])+(Subscript[a, 4])α (Subscript[δ, e])+(Subscript[a, 5])(α^2))+((q c)/(2 𝒱))((Subscript[b, 0])+(Subscript[b, 1])α+(Subscript[b, 2])(α^2)));
𝒵=dim((Subscript[d, 0])+(Subscript[d, 1])α+(Subscript[d, 2])(α^2)+(Subscript[d, 3])(Subscript[δ, e])+((q c)/(2 𝒱))((Subscript[e, 0])+(Subscript[e, 1])α +(Subscript[e, 2])(α^2)));
ℳ=dim(((Subscript[m, 0])+(Subscript[m, 1])α+(Subscript[m, 2])(Subscript[δ, e])+(Subscript[m, 3])α (Subscript[δ, e])+(Subscript[m, 4])(Subscript[δ, e]^2))+((q c)/(2 𝒱))((Subscript[n, 0])+(Subscript[n, 1])α+(Subscript[n, 2])(α^2)));

The aerodynamic and model parameters:

pars={(Subscript[a, 0])->-0.019,(Subscript[a, 1])->0.213,(Subscript[a, 2])->-0.3,(Subscript[a, 3])->-0.0033,(Subscript[a, 4])->-0.206,(Subscript[a, 5])->0.7,(Subscript[b, 0])->0.48,(Subscript[b, 1])->8.6,(Subscript[b, 2])->11.3,(Subscript[d, 0])->-0.13,(Subscript[d, 1])->-4.2,(Subscript[d, 2])->4.77,(Subscript[d, 3])->-10.2,(Subscript[e, 0])->-30.5,(Subscript[e, 1])->-41.3,(Subscript[e, 2])->320.,(Subscript[m, 0])->-0.0201,(Subscript[m, 1])->0.0466,(Subscript[m, 2])->-0.601,(Subscript[m, 3])->-0.0806,(Subscript[m, 4])->0.0832,(Subscript[n, 0])->-5.1,(Subscript[n, 1])->-3.55,(Subscript[n, 2])->-35.,m->7000,ρ->1.225,g->9.8,𝒮->35,c->3.5,𝒥->75000};

Use α==γ+θ, where γ is the flight path angle and θ the pitch angle:

f=f/.pars/.α->γ+θ//Simplify;

Find the steady states for steady (q==0), level (γ==0) flight at a specific speed (𝒱==262):

op={q->0,γ->0,𝒱->262};

sols=FindRoot[Cases[Thread[(f/.op)==0],Except[True]],{{θ,0},{(Subscript[δ, e]),0},{𝒯,1000}}]

scenario=Join[op,sols];

Define state variables and initial values:

{state,in}={scenario[[1;;4]],scenario[[5;;6]]};

The nonlinear state-space model of the aircraft with states x=={q,γ,𝒱,θ} and inputs {(Subscript[δ, e]),𝒯}:

nsys=NonlinearStateSpaceModel[{f,{γ,𝒱}},state,in];

Style[nsys,Small]

The 2×2 transfer function representation of the linearized system:

tfm=TransferFunctionModel[nsys]

The system is unstable due to the poles in the right half-plane:

Select[Flatten@TransferFunctionPoles[tfm],Re[#]>0&]

It is also nonminimum phase due to the zeros in the right half-plane:

Select[Flatten@TransferFunctionZeros[tfm],Re[#]>0&]

The (RefLink[BodePlot, paclet:ref/BodePlot]) shows that the velocity 𝒱 can be affected more than the flight path angle γ:

BodePlot[tfm,PlotLegends->{(Subscript[δ, e])↦γ,𝒯↦γ,(Subscript[δ, e])↦𝒱,𝒯↦𝒱}]

The six-degree-of-freedom equations of motion of an aircraft. The rotation matrix for a rotation ϵ about an axis k: (WebLink[», http://store.doverpublications.com/0486445224.html])

R[ϵ_,k_]:=RotationMatrix[ϵ,UnitVector[3,k]]

The rotation matrices for the Euler angles ϕ, θ, and ψ:

MatrixForm/@{R[ϕ,1],R[θ,2],R[ψ,3]}

The matrix transformation of a vector from the body-fixed to the earth-fixed axes:

(T=R[ψ,3].R[θ,2].R[ϕ,1])//MatrixForm

The inverse transformation from the earth-fixed to the body-fixed axes:

(S=R[-ϕ,1].R[-θ,2].R[-ψ,3])//MatrixForm

Verify they are inverses:

MatrixForm/@{S.T,T.S}//Simplify

A figure showing the earth-fixed axes {(Subscript[X, E]),(Subscript[X, E]),(Subscript[Z, E])} and body-fixed axes {X,Y,Z}:

The Euler angle rates in terms of the angular velocity components p, q, and r:

ω={p,q,r};

Solve[Thread[{ϕ',0,0}.R[ϕ,1]+{0,θ',0}.R[θ,2].R[ϕ,1]+{0,0,ψ'}.T==ω],{ϕ',θ',ψ'}]//Simplify

The kinematic equations for the Euler angles:

keuler=NonlinearStateSpaceModel[{ϕ',θ',ψ'}/.%,{ϕ,θ,ψ},{}]

The kinematic equations for the flight path variables x, y, and z:

kfpath=NonlinearStateSpaceModel[{T.{u,v,w}},{x,y,z},{}]

The inertia matrix, assuming that the x-z plane is a plane of symmetry:

ℐ=(({{(Subscript[𝒥, 𝓍]), 0, -(Subscript[𝒥, 𝓍𝓏])}, {0, (Subscript[𝒥, 𝓎]), 0}, {-(Subscript[𝒥, 𝓍𝓏]), 0, (Subscript[𝒥, 𝓏])}}));

The angular momentum 𝒽 can be computed as 𝒽==ℐ.ω:

𝒽=ℐ.ω

A figure showing the forces and moments acting on the aircraft:

The state equations of the angular velocity can be obtained by solving the moment equation ℳ==𝒽'+ω×𝒽, where ℳ is the vector of aerodynamic moments:

Thread[{(Subscript[ℳ, 𝓍]),(Subscript[ℳ, 𝓎]),(Subscript[ℳ, 𝓏])}==ℐ.{p',q',r'}+ω\[Cross]𝒽];

{p',q',r'}/.Solve[%,{p',q',r'}][[1]]

The dynamics of the rotational motion:

drot=NonlinearStateSpaceModel[{%},{p,q,r},{(Subscript[ℳ, 𝓍]),(Subscript[ℳ, 𝓎]),(Subscript[ℳ, 𝓏])}]

The forces acting on the aircraft are the aerodynamic forces {𝒳,𝒴,𝒵}, its weight, and the thrust 𝒯:

ℱ={𝒳,𝒴,𝒵}+S.{0,0,m g}+{𝒯,0,0}

The dynamics of the translational motion can be obtained from Newton's law ℱ==m (𝓋'+ω×𝓋):

dtrans=NonlinearStateSpaceModel[{(ℱ/m)-ω\[Cross]{u,v,w}},{u,v,w},{𝒳,𝒴,𝒵}]

The complete equations of motion for the aircraft:

aircraft=SystemsModelMerge[{keuler,kfpath,drot,dtrans}]

The longitudinal dynamics are the dynamics for states u, w, q, and θ:

SystemsModelExtract[aircraft,All,{10,12,8,2},{10,12,8,2}]

The lateral dynamics are the dynamics for the states v, p, r, and ϕ:

SystemsModelExtract[aircraft,All,{11,7,9,1},{11,7,9,1}]

OpenersExampleSubsection7(Spacer1)Extended Kalman Filter  (1)

Design an extended Kalman filter to track the motion of a wheeled robot:

The model of the robot:

a={0,0,0,0};
b={{Cos[θ+ϕ],0},{Sin[θ+ϕ],0},{Sin[θ],0},{0,1}};
xx={x,y,ϕ,θ};

robot=AffineStateSpaceModel[{a,b,{x,y,θ}},{x,y,ϕ,θ},{v,w}]

All the measurements are assumed to be noisy, with covariance R:

R=0.1IdentityMatrix[3]

The gain K of the filter is based on the covariance P of the states:

P=Array[(Subscript[p, ##])&,{4,4}];

B=D[{x,y,θ},{xx}];

K=P.B\[Transpose].Inverse[R]//Chop

The right-hand side of the differential equation for the estimated states with noisy measurements {(Subscript[x, m]),(Subscript[y, m]),(Subscript[θ, m])}:

rhs1=a+b.{v,w}+P.B\[Transpose].Inverse[R].({(Subscript[x, m]),(Subscript[y, m]),(Subscript[θ, m])}-{x,y,θ});

The right-hand side of the differential equation for the covariance matrix P:

A=D[a+b.{v,w},{xx}];

rhs2=Flatten[A.P+P.A\[Transpose]-P.B\[Transpose].Inverse[R].B.P];

Assemble the estimator using (RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]):

rhs=Join[rhs1,rhs2];

Join[xx,Flatten@MapThread[Rule,{Array[(Subscript[p, ##])&,{4,4}],10 IdentityMatrix[4]},2]];

ekf=NonlinearStateSpaceModel[{rhs,{x,y,θ}},%,{v,w,(Subscript[x, m]),(Subscript[y, m]),(Subscript[θ, m])}]

Simulate the robot from initial position {1,-1,10 °,0} and a set of inputs:

inps={UnitStep[t]-0.7UnitStep[t-1],UnitStep[t-1]-UnitStep[t-2]};

or=OutputResponse[{robot,{1,-1,10°,0}},inps,{t,0,20}];

Plot[or,{t,0,20},PlotLegends->{"x","y","θ"}]

The noisy measurements:

(Interpolation[Thread[{Range[0,20],#}],t]&/@Table[RandomVariate[NormalDistribution[0,σ],{21}],{σ,{0.1,0.1,0.1}}]);

orn=or+%;

Plot[orn,{t,0,20},PlotLegends->{"xm","ym","θm"}]

Simulate the response of the filter using the inputs to the system and the noisy measurements:

orf=OutputResponse[ekf,Join[inps,orn],{t,0,20}];

Compare the actual, noisy, and filtered values of the variable x:

Plot[{or[[1]],orn[[1]],orf[[1]]},{t,0,20},PlotLegends->{"x","xm","xf"}]

Variable y:

Plot[{or[[2]],orn[[2]],orf[[2]]},{t,0,20},PlotLegends->{"y","ym","yf"}]

Variable θ:

Plot[{or[[3]],orn[[3]],orf[[3]]},{t,0,20},PlotRange->All,PlotLegends->{"θ","θm","θf"}]

OpenersExampleSection5(Spacer1)Properties & Relations  (3)

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]) converts to (RefLink[AffineStateSpaceModel, paclet:ref/AffineStateSpaceModel]) by linearizing inputs:

AffineStateSpaceModel[(NonlinearStateSpaceModelFull[-(Subscript[x, 2]), u+(u^2)-(Subscript[x, 1])+u (Subscript[x, 1])+(Subscript[x, 2])+u (Subscript[x, 2])+(Subscript[x, 1]) (Subscript[x, 2]), (Subscript[x, 1]), {(Subscript[x, 1]),0}, {(Subscript[x, 2]),0}, \[Null], \[Null], {u}Automatic, ])]

Conversion the other way is exact:

NonlinearStateSpaceModel[%]

(RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]) converts to (RefLink[StateSpaceModel, paclet:ref/StateSpaceModel]) by linearizing states and inputs:

StateSpaceModel[(NonlinearStateSpaceModelFull[-(Subscript[x, 2]), u+(u^2)-(Subscript[x, 1])+u (Subscript[x, 1])+(Subscript[x, 2])+u (Subscript[x, 2])+(Subscript[x, 1]) (Subscript[x, 2]), (Subscript[x, 1]), {(Subscript[x, 1]),0}, {(Subscript[x, 2]),0}, \[Null], \[Null], {u}Automatic, ])]

Conversion the other way is exact:

NonlinearStateSpaceModel[%]

Convert to (RefLink[TransferFunctionModel, paclet:ref/TransferFunctionModel]) by state and input linearization:

TransferFunctionModel[(NonlinearStateSpaceModelFull[-(Subscript[x, 2]), u+(u^2)-(Subscript[x, 1])+u (Subscript[x, 1])+(Subscript[x, 2])+u (Subscript[x, 2])+(Subscript[x, 1]) (Subscript[x, 2]), (Subscript[x, 1]), {(Subscript[x, 1]),0}, {(Subscript[x, 2]),0}, \[Null], \[Null], {u}Automatic, ])]

Conversion the other way is exact:

NonlinearStateSpaceModel[%]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[AffineStateSpaceModel, paclet:ref/AffineStateSpaceModel])  ▪  (RefLink[StateSpaceModel, paclet:ref/StateSpaceModel])  ▪  (RefLink[FullInformationOutputRegulator, paclet:ref/FullInformationOutputRegulator])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Nonlinear Control Systems, paclet:guide/NonlinearControlSystems])}, {▪(RefLinkPlain[Control Systems, paclet:guide/ControlSystems])}})}})