www.gusucode.com > ident 案例代码 matlab源码程序 > ident/LowLevelNonlinearityEvaluationExample.m

    %% Low-Level Nonlinearity Evaluation
%% Perform a low-level computation
% This examples performs a low-level computation of the nonlinearity
% response for the |sigmoidnet| network function:
%%
%
% $$\begin{array}{l} F(x) = (x - r)PL + {a_1}f\left( {\left( {x - r}
% \right)Q{b_1} + {c_1}} \right) +  \ldots \\ {\rm{ }} + {a_n}f\left(
% {\left( {x - r} \right)Q{b_n} + {c_n}} \right) + d \end{array}$$
%
% where _f_ is the sigmoid function, given by the following equation:
%%
%
% $$f(z) = \frac{1}{{{e^{ - z}} + 1}}$$
%%
% In |F(x)|, the input to the sigmoid function is |x-r|. |x| is the regressor
% value and |r| is regressor mean, computed from the estimation data.
% ${a_n}$ , ${n_n}$, and ${c_n}$ are the network parameters stored in the
% model property |M.nl.par|, where |M| is an |idnlarx| object.
%%
% Compute the output value at time t=1, when the regressor values are |x=[estData.y(1),estData.u(2)]|:
%
% Estimate model from sample data.

% Copyright 2015 The MathWorks, Inc.

load twotankdata
estData = iddata(y,u,0.2,'Tstart',0);
M = nlarx(estData,[1 1 0],'sig');
NL = M.Nonlinearity;
%%
% Assign values to the parameters in the expression for |F(x)|.
x = [estData.y(1),estData.u(2)]; % regressor values at t=1
r = NL.Parameters.RegressorMean;
P = NL.Parameters.LinearSubspace;
L = NL.Parameters.LinearCoef;
d = NL.Parameters.OutputOffset;
Q = NL.Parameters.NonLinearSubspace;
aVec = NL.Parameters.OutputCoef;   % [a_1; a_2; ...]
cVec = NL.Parameters.Translation;  % [c_1; c_2; ...]
bMat = NL.Parameters.Dilation;     % [b_1; b_2; ...]
%%
% Compute the linear portion of the response (plus offset).
yLinear = (x-r)*P*L+d;
%%
% Compute the nonlinear portion of the response.
f = @(z)1/(exp(-z)+1); % anonymous function for sigmoid unit
yNonlinear = 0;
for k = 1:length(aVec)
    fInput = (x-r)*Q* bMat(:,k)+cVec(k);
    yNonlinear = yNonlinear+aVec(k)*f(fInput);
end
%%
% Compute total response |y = F(x) = yLinear + yNonlinear|.
y = yLinear + yNonlinear;
%%
% |y| is equal to |evaluate(NL,x)|.