# Construct a Nonlinear Estimator

Construct a nonlinear estimator using a predator-prey model to estimate the snowshoe hare population based on the lynx population. » The input to the model is and the output is .

 In:= Xpars = {\[ScriptR] -> 2.1, \[ScriptA] -> 3.2, \[ScriptB] -> 0.4, \[ScriptC] -> 50, \[ScriptD] -> 0.55, \[Kappa] -> 150};
 In:= Xsys = AffineStateSpaceModel[ {{-((\[ScriptA] \[ScriptH] \[ScriptL])/(\ \[ScriptC] + \[ScriptH])) + \[ScriptH] \[ScriptR] (1 - \[ScriptH]/\ \[Kappa]), -\[ScriptD] \[ScriptL] + (\[ScriptA] \[ScriptB] \[ScriptH] \ \[ScriptL])/(\[ScriptC] + \[ScriptH])}, {{ \[ScriptH] (1 - \ \[ScriptH]/\[Kappa]) }, {0 }}, {\[ScriptL]}, {{ 0 }}}, {{\[ScriptH], \ -((\[ScriptC] \[ScriptD])/(-\[ScriptA] \[ScriptB] + \[ScriptD]))}, {\ \[ScriptL], (\[ScriptB] \[ScriptC] \[ScriptR] (-\[ScriptC] \[ScriptD] \ + \[ScriptA] \[ScriptB] \[Kappa] - \[ScriptD] \ \[Kappa]))/((-\[ScriptA] \[ScriptB] + \[ScriptD])^2 \[Kappa])}}, \ {Subscript[\[FormalU], 1]}, {Automatic}, Automatic , SamplingPeriod -> None] /. pars;

The values of the initial population and a periodically varying food supply.

 In:= Xic = {80, 25}; \[ScriptF] = 1.1 + Cos[2 \[Pi] t];

The populations also vary periodically.

 In:= Xsr = StateResponse[{sys, ic}, \[ScriptF], {t, 0, 40}]; Plot[sr, {t, 0, 40}, PlotLegends -> {"hare", "lynx"}]
 Out= This limit-cycle behavior can also be seen on a parametric plot.

 In:= XParametricPlot[sr, {t, 0, 40}, Frame -> True, FrameLabel -> {"hare", "lynx"}]
 Out= Compute a set of estimator gains based on the linearized model.

 In:= X\[ScriptG] = EstimatorGains[StateSpaceModel[sys], {-1, -2}]
 Out= Construct the nonlinear estimator using the computed gains.

 In:= X\[ScriptCapitalL] = StateOutputEstimator[sys, \[ScriptG]]
 Out= The observer inputs are and .

 In:= X\[ScriptCapitalU] = Join[{\[ScriptF]}, OutputResponse[{sys, ic}, \[ScriptF], {t, 0, 30}]]
 Out= After initial transients, the estimated value converges to the actual one.

 In:= XSubscript[\[ScriptH], estim] = OutputResponse[\[ScriptCapitalL], \[ScriptCapitalU], {t, 0, 30}][[ 1]]; Plot[{sr[], Subscript[\[ScriptH], estim]}, {t, 0, 5}, PlotLegends -> {"Actual", "Estimated"}]
 Out= ## Mathematica

Questions? Comments? Contact a Wolfram expert »