# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# 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:

$\begin{array}{l}\stackrel{˙}{x}\left(t\right)=Ax\left(t\right)+Bu\left(t\right)+Ke\left(t\right)\\ y\left(t\right)=Cx\left(t\right)+Du\left(t\right)+e\left(t\right)\end{array}$

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

$\begin{array}{l}x\left[k+1\right]=Ax\left[k\right]+Bu\left[k\right]+Ke\left[k\right]\\ y\left[k\right]=Cx\left[k\right]+Du\left[k\right]+e\left[k\right]\end{array}$

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 sample 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 sample 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

collapse all

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 = 'motorDynamics'; 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 motorDynamics.m to return the , , , , and matrices. motorDynamics.m also returns the initial conditions, . The motor constant, , is defined in motorDynamics.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 .

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. Save this function as LinearPendulum.m such that it is in the MATLAB® search path.

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 

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 sample time.

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.

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 = 'motorDynamics'; 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';

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

odefun1 = @motorDynamics; parameters1 = [1 2]; fcn_type = 'cd'; optional_args1 = 1; sys1 = idgrey(odefun1,parameters1,fcn_type,optional_args1); odefun2 = 'motorDynamics'; 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 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: $\begin{array}{c}xn\left(t\right)=Ax\left(t\right)+Bu\left(t\right)+Ke\left(t\right);x\left(0\right)={x}_{0}\\ y\left(t\right)=Cx\left(t\right)+Du\left(t\right)+e\left(t\right)\end{array}$ In discrete time xn(t)=x(t+Ts) and in continuous time, $xn\left(t\right)=\stackrel{˙}{x}\left(t\right)$. 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 values: '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 sample 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 sample 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, specified as one of the following: Character vector — For first-order models, for example, 'velocity'.Cell array of character vectors — For models with two or more states'' — For unnamed states. Default: '' for all states StateUnit State units, specified as one of the following: Character vector — For first-order models, for example, 'velocity'.Cell array of character vectors — For models with two or more states'' — For unnamed states. Use StateUnit to keep track of the units each state is expressed in. StateUnit has no effect on system behavior. Default: '' 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. Structure.Function — Name or function handle of the MATLAB function used to create the idgrey model.Structure.FunctionType — 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.Specify parameter units and labels as character vectors. For example, 'Time'.Structure.ExtraArguments — 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 Summary report that contains information about the estimation options and results when the grey-box model is obtained using the greyest estimation command. Use Report to query a model for how it was estimated, including its: Estimation methodEstimation optionsSearch termination conditionsEstimation data fit and other quality metrics The contents of Report are irrelevant if the model was created by construction. odefun = 'motorDynamics'; m = idgrey(odefun,1,'cd',0.25,0); m.Report.OptionsUsed ans = [] If you obtain the grey-box model using estimation commands, the fields of Report contain information on the estimation data, options, and results. load(fullfile(matlabroot,'toolbox','ident','iddemos','data','dcmotordata')); data = iddata(y,u,0.1,'Name','DC-motor'); odefun = 'motorDynamics'; init_sys = idgrey('motorDynamics',1,'cd',0.25,0); m = greyest(data,init_sys); m.Report.OptionsUsed InitialState: 'auto' DisturbanceModel: 'auto' Focus: 'prediction' EstCovar: 1 Display: 'off' InputOffset: [] OutputOffset: [] Regularization: [1x1 struct] OutputWeight: [] SearchMethod: 'auto' SearchOption: [1x1 idoptions.search.identsolver] Advanced: [1x1 struct] Report is a read-only property. For more information on this property and how to use it, see the Output Arguments section of the corresponding estimation command reference page and Estimation Report. 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 sample time Ts. For example, InputDelay = 3 means a delay of three sample times. 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 Sample time. For continuous-time models, Ts = 0. For discrete-time models, Ts is a positive scalar representing the sample time expressed in the unit specified by the TimeUnit property of the model. To denote a discrete-time model with unspecified sample 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 Units for the time variable, the sample time Ts, and any time delays in the model, specified as one 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, specified as one of the following: Character vector — For single-input models, for example, 'controls'.Cell array of character vectors — For multi-input models. 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 plotsExtracting subsystems of MIMO systemsSpecifying connection points when interconnecting models Default: '' for all input channels InputUnit Input channel units, specified as one of the following: Character vector — For single-input models, for example, 'seconds'.Cell array of character vectors — For multi-input models. Use InputUnit to keep track of input signal units. InputUnit has no effect on system behavior. Default: '' 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, specified as one of the following: Character vector — For single-output models. For example, 'measurements'.Cell array of character vectors — For multi-output models. 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 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 plotsExtracting subsystems of MIMO systemsSpecifying connection points when interconnecting models Default: '' for all output channels OutputUnit Output channel units, specified as one of the following: Character vector — For single-output models. For example, 'seconds'.Cell array of character vectors — For multi-output models. Use OutputUnit to keep track of output signal units. OutputUnit has no effect on system behavior. Default: '' for all output 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, specified as a character vector. For example, 'system_1'. Default: '' Notes Any text that you want to associate with the system, specified as a character vector or cell array of character vectors. For example, 'System is MIMO'. Default: {} UserData Any type of data you want to associate with system, specified as 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. For model arrays generated by linearizing a Simulink® model at multiple parameter values or operating points, the software populates SamplingGrid automatically with the variable values that correspond to each entry in the array. For example, the Simulink Control Design™ commands linearize and slLinearizer populate SamplingGrid in this way. Default: []