Skip to Main Content Skip to Search
Product Documentation

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:

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

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, in the form of ordinary differential or difference equations. You can also use idgrey models to prescribe complex relationships and constraints among the parameters that are not achievable by using structured state-space models (idss).

You can create an idgrey model using the idgrey command. You must 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

Create Grey-Box Model with Identifiable 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, τ, 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 τ.

Configure Identifiable Parameters of Grey-Box Model

Specify minimum constraints for the estimable parameters of an idgrey model.

Create an idgrey model.

odefun = 'ModalFormODE';

sigma1=0.1; 
sigma2=0.1; 
w1=1; 
w2=1;
B = [1 0 0 0]';
C = [1 1 1 1];

parameters = {'sigma1',sigma1;...
               'w1',w1;...
               'sigma2',sigma2;...
               'w2',w2;...
               'B',B;...
               'C',C};
fcn_type = 'c';

sys = idgrey(odefun,parameters,fcn_type);

sys is an idgrey model that is configured to use the function ModalFormODE to return the A, B, C, and D matrices. The code for the function ModalFormODE is:

function [A,B,C,D] = ModalFormODE(sigma1,w1,sigma2,w2,Bpar,Cpar,varargin)
%MODALFORMODE Function that parameterizes a 4th order state-space model in
%modal form.
%
% Parameters:
%   sigma1: The absolute value of the real part of the first
%           complex-conjugate pair of poles. Positive scalar.
%       w1: The absolute value of the imaginary part of the first
%           complex-conjugate pair of poles. Positive scalar.
%   sigma2: Similar to sigma1. Positive scalar.
%       w2: Similar to w1. Positive scalar.
%     BPar: A 4-by-1 real vector. No constraints on coefficients.
%     CPar: A 1-by-4 real vector. No constraints on coefficients.
%
% This file parameterizes the state-space model in continuous-time only.
A1 = [-sigma1, w1; -w1, -sigma1];
A2 = [-sigma2, w2; -w2, -sigma2];
A = blkdiag(A1,A2);
B = Bpar;
C = Cpar;
D = 0;
end

The function defines sigma1, w1, sigma2, w2, Bpar, and Cpar as estimable parameters.

Specify minimum constraints for some of the estimable parameters.

sys.Structure.Parameters(1).Minimum = 0;
sys.Structure.Parameters(2).Minimum = 0;
sys.Structure.Parameters(3).Minimum = 0;
sys.Structure.Parameters(4).Minimum = 0;

The first four parameters in sys.Structure.Parameters are sigma1, w1, sigma2, and w2. This code specifies 0 as the minimum value for these parameters.

You can use pem or greyest to estimate the estimable parameters of sys. When you do so, the software enforces the constraints specified in sys.Structure in estimating the parameters.

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.

You can 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';

Array of Grey-Box Models

Create an 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,...)

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

In discrete time xn(t)=x(t+Ts) and in continuous time, xn(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 and 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 takes 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.

    Else, 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.

As a,b,c,d are returned by the ODE function associated with the idgrey model, 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 5 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, unless it is designated to be estimable using 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, unless it is designated to be estimable using the DisturbanceModel estimation option.

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

StateName

State names. Set StateName to a string for first-order models, or to a cell array of strings for models with two or more states. 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. Set StateUnit to a string for first-order models, or to a cell array of strings for models with two or more states. 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 specifying whether the parameter is a free estimation variable. If you want to fix the value of a parameter during estimation, set the 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 delays. InputDelay is a numeric vector specifying a time delay for each input channel. 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, where each entry is a numerical value representing 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 for all input channels

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, any time delays in the model (for continuous-time models), and the sampling time Ts (for discrete-time models). TimeUnit can take the following values:

  • 'nanoseconds'

  • 'microseconds'

  • 'milliseconds'

  • 'seconds'

  • 'minutes'

  • 'hours'

  • 'days'

  • 'weeks'

  • 'months'

  • 'years'

Changing this property 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 software automatically expands the input names to {'controls(1)';'controls(2)'}.

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. Set InputUnit to a string for single-input model, or to a cell array of strings for a multi-input model. 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 whose field names are the group names and whose field values are the input channels belong 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 software automatically expands the output names to {'measurements(1)';'measurements(2)'}.

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. Set OutputUnit to a string for single-input model, or to a cell array of strings for a multi-input model. 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 whose field names are the group names and whose field values are the output channels belong 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 wish 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: []

See Also

getpvec | greyest | greyestOptions | idnlgrey | idss | pem | setpvec | ssest

  


Free Control Systems Interactive Kit

Learn more about resources for designing, testing, and implementing control systems.

Get free kit

Trials Available

Try the latest control systems products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS