idgrey

Linear ODE (grey-box model) with identifiable parameters

Syntax

sys = idgrey(odefun,parameters,fcn_type)
sys = idgrey(odefun,parameters,fcn_type,optional_args)
sys = idgrey(odefun,parameters,fcn_type,optional_args,Ts)
sys = idgrey(odefun,parameters,fcn_type,optional_args,Ts,Name,Value)

Description

sys = idgrey(odefun,parameters,fcn_type) creates a linear grey-box model with identifiable parameters, sys. odefun specifies the user-defined function that relates the model parameters, parameters, to its state-space representation.

sys = idgrey(odefun,parameters,fcn_type,optional_args) creates a linear grey-box model with identifiable parameters using the optional arguments required by odefun.

sys = idgrey(odefun,parameters,fcn_type,optional_args,Ts) creates a linear grey-box model with identifiable parameters with the specified sample time, Ts.

sys = idgrey(odefun,parameters,fcn_type,optional_args,Ts,Name,Value) creates a linear grey-box model with identifiable parameters with additional options specified by one or more Name,Value pair arguments.

Object Description

An idgrey model represents a system as a continuous-time or discrete-time state-space model with identifiable (estimable) coefficients.

A state-space model of a system with input vector, u, output vector, y, and disturbance, e, takes the following form in continuous time:

x˙(t)=Ax(t)+Bu(t)+Ke(t)y(t)=Cx(t)+Du(t)+e(t)

In discrete time, the state-space model takes the form:

x[k+1]=Ax[k]+Bu[k]+Ke[k]y[k]=Cx[k]+Du[k]+e[k]

For idgrey models, the state-space matrices A, B, C, and D are expressed as a function of user-defined parameters using a MATLAB® function. You access estimated parameters using sys.Structures.Parameters, where sys is an idgrey model.

Use an idgrey model when you know the system of equations governing the system dynamics explicitly. You should be able to express these dynamics in the form of ordinary differential or difference equations. You specify complex relationships and constraints among the parameters that cannot be done through structured state-space models (idss).

You can create an idgrey model using the idgrey command. To do so, write a MATLAB function that returns the A, B, C, and D matrices for given values of the estimable parameters and sampling time. The MATLAB function can also return the K matrix and accept optional input arguments. The matrices returned may represent a continuous-time or discrete-time model, as indicated by the sampling time.

Use the estimating functions pem or greyest to obtain estimated values for the unknown parameters of an idgrey model.

You can convert an idgrey model into other dynamic systems, such as idpoly, idss, tf, ss etc. You cannot convert a dynamic system into an idgrey model.

Examples

expand all

Create Grey-Box Model with Estimable Parameters

Create an idgrey model to represent a DC motor. Specify the motor time-constant as an estimable parameter and that the ODE function can return continuous- or discrete-time state-space matrices.

Create the idgrey model.

odefun = 'motor';
parameters = 1;
fcn_type = 'cd';
optional_args = 0.25;
Ts = 0;
sys = idgrey(odefun,parameters,fcn_type,optional_args,Ts);

sys is an idgrey model that is configured to use the shipped file motor.m to return the $A$, $B$, $C$, $D$, and $K$ matrices. motor.m also returns the initial conditions, $X0$. The motor constant, $\tau$, is defined in motor.m as an estimable parameter, and parameters = 1 specifies its initial value as 1.

You can use pem or greyest to refine the estimate for $\tau$.

Configure Estimable Parameter of Grey-Box Model

Specify the known parameters of a grey-box model as fixed for estimation. Also specify a minimum bound for an estimable parameter.

Create an ODE file that relates the pendulum model coefficients to its state-space representation.

function [A,B,C,D] = LinearPendulum(m,g,l,b,Ts)
A = [0 1; -g/l, -b/m/l^2];
B = zeros(2,0);
C = [1 0];
D = zeros(1,0);
end

Save this function as LinearPendulum.m such that it is in the MATLAB search path.

In this function:

  • m is the pendulum mass.

  • g is the gravitational acceleration.

  • l is the pendulum length.

  • b is the viscous friction coefficient.

  • Ts is the model sampling period.

Create a linear grey-box model associated with the ODE function.

odefun = 'LinearPendulum';

m = 1;
g = 9.81;
l = 1;
b = 0.2;
parameters = {'mass', m; 'gravity', g; 'length', l; 'friction', b}

fcn_type = 'c';

sys = idgrey(odefun,parameters,fcn_type);

sys has four parameters.

Specify the known parameters, m, g, and l, as fixed for estimation.

sys.Structure.Parameters(1).Free = false;
sys.Structure.Parameters(2).Free = false;
sys.Structure.Parameters(3).Free = false;

m, g, and l are the first three parameters of sys.

Specify a zero lower bound for b, the fourth parameter of sys.

sys.Structure.Parameters(4).Minimum = 0;

Similarly, to specify an upper bound for an estimable parameter, use the Maximum field of the parameter.

Specify Additional Attributes of Grey-Box Model

Create a grey-box model with identifiable parameters. Name the input and output channels of the model, and specify seconds for the model time units.

Use Name,Value pair arguments to specify additional model properties on model creation.

odefun = 'motor';
parameters = 1;
fcn_type = 'cd';
optional_args = 0.25;
Ts = 0;
sys = idgrey(odefun,parameters,fcn_type,optional_args,Ts,'InputName','Voltage',...
            'OutputName',{'Angular Position','Angular Velocity'});

To change or specify more attributes of an existing model, you can use dot notation. For example:

sys.TimeUnit = 'seconds';

Create Array of Grey-Box Models

Use the stack command to create an array of linear grey-box models.

odefun1 = @motor;
parameters1 = [1 2];
fcn_type = 'cd';
optional_args1 = 1;
sys1 = idgrey(odefun1,parameters1,fcn_type,optional_args1);

odefun2 = 'motor';
parameters2 = {[1 2]};
optional_args2 = 0.5;
sys2 = idgrey(odefun2,parameters2,fcn_type,optional_args2);

sysarr = stack(1,sys1,sys2);

stack creates a 2-by-1 array of idgrey models, sysarr.

Input Arguments

odefun

MATLAB function that relates the model parameters to its state-space representation.

odefun specifies, as a string, the name of a MATLAB function (.m, .p, a function handle or .mex* file). This function establishes the relationship between the model parameters, parameters, and its state-space representation. The function may optionally relate the model parameters to the disturbance matrix and initial states.

If the function is not on the MATLAB path, then specify the full file name, including the path.

The syntax for odefun must be as follows:

[A,B,C,D] = odefun(par1,par2,...,parN,Ts,optional_arg1,optional_arg2,...)

The function outputs describe the model in the following linear state-space innovations form:

xn(t)=Ax(t)+Bu(t)+Ke(t);x(0)=x0y(t)=Cx(t)+Du(t)+e(t)

In discrete time xn(t)=x(t+Ts) and in continuous time, xn(t)=x˙(t).

par1,par2,...,parN are model parameters. Each entry may be a scalar, vector or matrix.

Ts is the sample time.

optional_arg1,optional_arg2,... are the optional inputs that odefun may require. The values of the optional input arguments are unchanged through the estimation process. However, the values of par1,par2,...,parN are updated during estimation to fit the data. Use optional input arguments to vary the constants and coefficients used by your model without editing odefun.

The disturbance matrix, K, and the initial state values, x0, are not parametrized. Instead, these values are determined separately, using the DisturbanceModel and InitialState estimation options, respectively. For more information regarding the estimation options, see greyestOptions.

A good choice for achieving the best simulation results is to set the DisturbanceModel option to 'none', which fixes K to zero.

(Optional) Parameterizing Disturbance: odefun can also return the disturbance component, K, using the syntax:

[A,B,C,D,K] = odefun(par1,par2,...,parN,Ts,optional_arg1,optional_arg2,...)

If odefun returns a value for K that contains NaN values, then the estimating function assumes that K is not parameterized. In this case, the value of the DisturbanceModel estimation option determines how K is handled.

(Optional) Parameterizing Initial State Values: To make the model initial states, X0, dependent on the model parameters, use the following syntax for odefun:

[A,B,C,D,K,X0] = odefun(par1,par2,...,parN,Ts,optional_arg1,optional_arg2,...)

If odefun returns a value for X0 that contains NaN values, then the estimating function assumes that X0 is not parameterized. In this case, X0 may be fixed to zero or estimated separately, using the InitialStates estimation option.

parameters

Initial values of the parameters required by odefun.

Specify parameters as a cell array containing the parameter initial values. If your model requires only one parameter, which may itself be a vector or a matrix, you may specify parameters as a matrix.

You may also specify parameter names using an N-by-2 cell array, where N is the number of parameters. The first column specifies the names, and the second column specifies the values of the parameters.

For example:

parameters = {'mass',par1;'stiffness',par2;'damping',par3}

fcn_type

Indicates whether the model is parameterized in continuous-time, discrete-time, or both.

fcn_type requires one of the following strings:

  • 'c'odefun returns matrices corresponding to a continuous-time system, regardless of the value of Ts.

  • 'd'odefun returns matrices corresponding to a discrete-time system, whose values may or may not depend on the value of Ts.

  • 'cd'odefun returns matrices corresponding to a continuous-time system, if Ts=0.

    Otherwise, if Ts>0, odefun returns matrices corresponding to a discrete-time system. Select this option to sample your model using the values returned by odefun, rather than using the software's internal sample time conversion routines.

optional_args

Optional input arguments required by odefun.

Specify optional_args as a cell array.

If odefun does not require optional input arguments, specify optional_args as {}.

Ts

Model sampling time.

If Ts is unspecified, it is assumed to be:

  • -1 — If fcn_type is 'd' or 'cd'.

    Ts = -1 indicates a discrete-time model with unknown sampling time.

  • 0 — If fcn_type is 'c'.

    Ts = 0 indicates a continuous-time model.

Name,Value

Specify optional comma-separated pairs of Name,Value arguments, where Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Use Name,Value arguments to specify additional properties of idgrey models during model creation. For example, idgrey(odefun,parameters,fcn_type,'InputName','Voltage') creates an idgrey model with the InputName property set to Voltage.

Properties

idgrey object properties include:

a,b,c,d

Values of state-space matrices.

  • a — State matrix A, an Nx-by-Nx matrix, as returned by the ODE function associated with the idgrey model. Nx is the number of states.

  • b — Input-to-state matrix B, an Nx-by-Nu matrix, as returned by the ODE function associated with the idgrey model. Nu is the number of inputs and Nx is the number of states.

  • c — State-to-output matrix C, an Ny-by-Nx matrix, as returned by the ODE function associated with the idgrey model. Nx is the number of states and Ny is the number of outputs.

  • d — Feedthrough matrix D, an Ny-by-Nu matrix, as returned by the ODE function associated with the idgrey model. Ny is the number of outputs and Nu is the number of inputs.

The values a,b,c,d are returned by the ODE function associated with the idgrey model. Thus, you can only read these matrices; you cannot set their values.

k

Value of state disturbance matrix, K

k is Nx-by-Ny matrix, where Nx is the number of states and Ny is the number of outputs.

  • If odefun parameterizes the K matrix, then k has the value returned by odefun. odefun parameterizes the K matrix if it returns at least five outputs and the value of the fifth output does not contain NaN values.

  • If odefun does not parameterize the K matrix, then k is a zero matrix of size Nx-by-Ny. Nx is the number of states and Ny is the number of outputs. The value is treated as a fixed value of the K matrix during estimation. To make the value estimable, use the DisturbanceModel estimation option.

  • Regardless of whether the K matrix is parameterized by odefun or not, you can set the value of the k property explicitly as an Nx-by-Ny matrix. Nx is the number of states and Ny is the number of outputs. The specified value is treated as a fixed value of the K matrix during estimation. To make the value estimable, use the DisturbanceModel estimation option.

To create an estimation option set for idgrey models, use greyestOptions.

StateName

State names. For first-order models, set StateName to a string. For models with two or more states, set StateName to a cell array of strings . Use an empty string '' for unnamed states.

Default: Empty string '' for all states

StateUnit

State units. Use StateUnit to keep track of the units each state is expressed in. For first-order models, set StateUnit to a string. For models with two or more states, set StateUnit to a cell array of strings. StateUnit has no effect on system behavior.

Default: Empty string '' for all states

Structure

Information about the estimable parameters of the idgrey model.

Structure stores information regarding the MATLAB function that parameterizes the idgrey model.

  • Strucutre.Function — Name or function handle of the MATLAB function used to create the idgrey model.

  • Structure.FcnType — Indicates whether the model is parameterized in continuous-time, discrete-time, or both.

  • Structure.Parameters — Information about the estimated parameters. Structure.Parameters contains the following fields:

    • Value — Parameter values. For example, sys.Structure.Parameters(2).Value contains the initial or estimated values of the second parameter.

      NaN represents unknown parameter values.

    • Minimum — Minimum value that the parameter can assume during estimation. For example, sys.Structure.Parameters(1).Minimum = 0 constrains the first parameter to be greater than or equal to zero.

    • Maximum — Maximum value that the parameter can assume during estimation.

    • Free — Boolean value specifying whether the parameter is estimable. If you want to fix the value of a parameter during estimation, set Free = false for the corresponding entry.

    • Scale — Scale of the parameter's value. Scale is not used in estimation.

    • Info — Structure array for storing parameter units and labels. The structure has Label and Unit fields.

      Use these fields for your convenience, to store strings that describe parameter units and labels.

  • Structure.ExtraArgs — Optional input arguments required by the ODE function.

  • Structure.StateName — Names of the model states.

  • Structure.StateUnit — Units of the model states.

NoiseVariance

The variance (covariance matrix) of the model innovations, e.

An identified model includes a white, Gaussian noise component, e(t). NoiseVariance is the variance of this noise component. Typically, the model estimation function (such as greyest or pem) determines this variance.

For SISO models, NoiseVariance is a scalar. For MIMO models, NoiseVariance is a Ny-by-Ny matrix, where Ny is the number of outputs in the system.

Report

Information about the estimation process.

Report contains the following fields:

  • Status — Whether model was obtained by construction, estimated, or modified after estimation.

  • Method — Name of estimation method used.

  • InitialState — Initial state handling during model estimation.

  • DisturbanceModel — Disturbance component (the K matrix) handling of the model during estimation.

  • Fit — Quantitative quality assessment of estimation, including percent fit to data and final prediction error.

  • Parameters — Estimated values of model parameters and their covariance

  • OptionsUsed — Options used during estimation (see greyestOptions).

  • RandState — Random number stream state at the start of estimation.

  • DataUsed — Attributes of the data used for estimation, such as name and sampling time.

  • Termination — Termination conditions for the iterative search scheme used for prediction error minimization, such as final cost value and stopping criterion.

InputDelay

Input delay for each input channel, specified as a scalar value or numeric vector. For continuous-time systems, specify input delays in the time unit stored in the TimeUnit property. For discrete-time systems, specify input delays in integer multiples of the sampling period Ts. For example, InputDelay = 3 means a delay of three sampling periods.

For a system with Nu inputs, set InputDelay to an Nu-by-1 vector. Each entry of this vector is a numerical value that represents the input delay for the corresponding input channel.

You can also set InputDelay to a scalar value to apply the same delay to all channels.

Default: 0

OutputDelay

Output delays.

For identified systems, like idgrey, OutputDelay is fixed to zero.

Ts

Sampling time.

For continuous-time models, Ts = 0. For discrete-time models, Ts is a positive scalar representing the sampling period expressed in the unit specified by the TimeUnit property of the model. To denote a discrete-time model with unspecified sampling time, set Ts = -1.

Changing this property does not discretize or resample the model.

For idgrey models, there is no unique default value for Ts. Ts depends on the value of fcn_type.

TimeUnit

String representing the unit of the time variable. This property specifies the units for the time variable, the sampling time Ts, and any time delays in the model. Use any of the following values:

  • 'nanoseconds'

  • 'microseconds'

  • 'milliseconds'

  • 'seconds'

  • 'minutes'

  • 'hours'

  • 'days'

  • 'weeks'

  • 'months'

  • 'years'

Changing this property has no effect on other properties, and therefore changes the overall system behavior. Use chgTimeUnit to convert between time units without modifying system behavior.

Default: 'seconds'

InputName

Input channel names. Set InputName to a string for single-input model. For a multi-input model, set InputName to a cell array of strings.

Alternatively, use automatic vector expansion to assign input names for multi-input models. For example, if sys is a two-input model, enter:

sys.InputName = 'controls';

The input names automatically expand to {'controls(1)';'controls(2)'}.

When you estimate a model using an iddata object, data, the software automatically sets InputName to data.InputName.

You can use the shorthand notation u to refer to the InputName property. For example, sys.u is equivalent to sys.InputName.

Input channel names have several uses, including:

  • Identifying channels on model display and plots

  • Extracting subsystems of MIMO systems

  • Specifying connection points when interconnecting models

Default: Empty string '' for all input channels

InputUnit

Input channel units. Use InputUnit to keep track of input signal units. For a single-input model, set InputUnit to a string. For a multi-input model, set InputUnit to a cell array of strings. InputUnit has no effect on system behavior.

Default: Empty string '' for all input channels

InputGroup

Input channel groups. The InputGroup property lets you assign the input channels of MIMO systems into groups and refer to each group by name. Specify input groups as a structure. In this structure, field names are the group names, and field values are the input channels belonging to each group. For example:

sys.InputGroup.controls = [1 2];
sys.InputGroup.noise = [3 5];

creates input groups named controls and noise that include input channels 1, 2 and 3, 5, respectively. You can then extract the subsystem from the controls inputs to all outputs using:

sys(:,'controls')

Default: Struct with no fields

OutputName

Output channel names. Set OutputName to a string for single-output model. For a multi-output model, set OutputName to a cell array of strings.

Alternatively, use automatic vector expansion to assign output names for multi-output models. For example, if sys is a two-output model, enter:

sys.OutputName = 'measurements';

The output names to automatically expand to {'measurements(1)';'measurements(2)'}.

When you estimate a model using an iddata object, data, the software automatically sets OutputName to data.OutputName.

You can use the shorthand notation y to refer to the OutputName property. For example, sys.y is equivalent to sys.OutputName.

Output channel names have several uses, including:

  • Identifying channels on model display and plots

  • Extracting subsystems of MIMO systems

  • Specifying connection points when interconnecting models

Default: Empty string '' for all input channels

OutputUnit

Output channel units. Use OutputUnit to keep track of output signal units. For a single-output model, set OutputUnit to a string. For a multi-output model, set OutputUnit to a cell array of strings. OutputUnit has no effect on system behavior.

Default: Empty string '' for all input channels

OutputGroup

Output channel groups. The OutputGroup property lets you assign the output channels of MIMO systems into groups and refer to each group by name. Specify output groups as a structure. In this structure, field names are the group names, and field values are the output channels belonging to each group. For example:

sys.OutputGroup.temperature = [1];
sys.InputGroup.measurement = [3 5];

creates output groups named temperature and measurement that include output channels 1, and 3, 5, respectively. You can then extract the subsystem from all inputs to the measurement outputs using:

sys('measurement',:)

Default: Struct with no fields

Name

System name. Set Name to a string to label the system.

Default: ''

Notes

Any text that you want to associate with the system. Set Notes to a string or a cell array of strings.

Default: {}

UserData

Any type of data you wish to associate with system. Set UserData to any MATLAB data type.

Default: []

SamplingGrid

Sampling grid for model arrays, specified as a data structure.

For arrays of identified linear (IDLTI) models that are derived by sampling one or more independent variables, this property tracks the variable values associated with each model. This information appears when you display or plot the model array. Use this information to trace results back to the independent variables.

Set the field names of the data structure to the names of the sampling variables. Set the field values to the sampled variable values associated with each model in the array. All sampling variables should be numeric and scalar valued, and all arrays of sampled values should match the dimensions of the model array.

For example, if you collect data at various operating points of a system, you can identify a model for each operating point separately and then stack the results together into a single system array. You can tag the individual models in the array with information regarding the operating point:

nominal_engine_rpm = [1000 5000 10000];
sys.SamplingGrid = struct('rpm', nominal_engine_rpm)

where sys is an array containing three identified models obtained at rpms 1000, 5000 and 10000, respectively.

Default: []

Was this topic helpful?