(Not recommended) Custom regressor for nonlinear ARX models
The customreg
command is not recommended. For
polynomial regressors, use polynomialRegressor
instead. For other custom regressors, use customRegressor
.
For more information, see Compatibility Considerations.
C
=customreg(Function
,Variables
)
C
=customreg(Function
,Variables
,Delays
,Vectorized
)
customreg
class represents arbitrary functions
of past inputs and outputs, such as products, powers, and other MATLAB^{®} expressions
of input and output variables.
You can specify custom regressors in addition to or instead of standard regressors for greater flexibility in modeling your data using nonlinear ARX models. For example, you can define regressors like tan(u(t1)), u(t1)^{2}, and u(t1)*y(t3).
For simpler regressor expressions, specify custom regressors
directly in the app or in the nlarx
estimation
command. For more complex expressions, create a customreg
object
for each custom regressor and specify these objects as inputs to the
estimation. Regardless of how you specify custom regressors, the toolbox
represents these regressors as customreg
objects.
Use getreg
to list the expressions
of all standard and custom regressors in your model.
A special case of custom regressors involves polynomial combinations
of past inputs and outputs. For example, it is common to capture nonlinearities
in the system using polynomial expressions like y(t−1)2, u(t−1)2, y(t−2)2,
y(t−1)*y(t−2), y(t−1)*u(t−1), y(t−
2)*u(t−1). At the command
line, use the polyreg
command
to generate polynomialtype regressors automatically by computing
all combinations of input and output variables up to a specified degree. polyreg
produces customreg
objects
that you specify as inputs to the estimation.
The nonlinear ARX model (idnlarx
object)
stores all custom regressors as the CustomRegressors
property.
You can list all custom regressors using m.CustomRegressors
,
where m
is a nonlinear ARX model. For MIMO models,
to retrieve the r
th custom regressor for output ky
,
use m.CustomRegressors{ky}(r)
.
Use the Vectorized
property to specify whether
to compute custom regressors using vectorized form during estimation.
If you know that your regressor formulas can be vectorized, set Vectorized
to 1
to
achieve better performance. To better understand vectorization, consider
the custom regressor function handle z=@(x,y)x^2*y
. x
and y
are
vectors and each variable is evaluated over a time grid. Therefore, z
must
be evaluated for each (xi,yi)
pair, and the results
are concatenated to produce a z
vector:
for k = 1:length(x) z(k) = x(k)^2*y(k) end
The above expression is a nonvectorized computation and tends
to be slow. Specifying a Vectorized
computation
uses MATLAB vectorization rules to evaluate the regressor expression
using matrices instead of the FOR
loop and results
in faster computation:
% ".*" indicates elementwise operation
z=(x.^2).*y
specifies
a custom regressor for a nonlinear ARX model. C
=customreg(Function
,Variables
)C
is
a customreg
object that stores custom regressor. Function
is
a function of input and output variables. Variables
represent
the names of model inputs and outputs in the function Function
.
Each input and output name must coincide with the InputName
and OutputName
properties
of the corresponding idnlarx
object.
The size of Variables
must match the number
of Function
inputs. For multipleoutput
models with p
outputs, the custom regressor is
a p
by1 cell array or an array of customreg
object,
where the ky
th entry defines the custom regressor
for output ky
. You must add these regressors to
the model
by assigning the CustomRegressors
model
property
or by using addreg
.
create
a custom regressor that includes the delays corresponding to inputs
or outputs in C
=customreg(Function
,Variables
,Delays
,Vectorized
)Arguments
. Delays
is
a vector of positive integers that represent the delays of Variables
variables
(default is 1 for each vector element). The size of Delays
must
match the size of Variables
. Vectorized
value
of 1
uses MATLAB vectorization rules to evaluate
the regressor expression Function
. By default, Vectorized
value
is 0
(false).
After creating the object, you can use get
or
dot notation to access the object property values. For example:
% List all property values get(C) % Get value of Arguments property C.Arguments
You can also use the set
function to set
the value of particular properties. For example:
set(C,'Vectorized',1)
Property Name  Description 

Function  Function handle or character vector representing a function of standards regressors. For example: cr = @(x,y) x*y 
Variables  Cell array of character vectors that represent the names
of model input and output variables in the function For
example, C = customreg(cr,{'y1','u1'},[2 3]) 
Delays  Vector of positive integers representing the delays
of Default: For example, C = customreg(cr,{'y1','u1'},[2 3]) 
Vectorized  Assignable values:
