MATLAB Examples

Create Function to Represent a Grey-Box Model

This example shows how to represent the structure of the following continuous-time model:

\dot x(t) = \left[ {\begin{array}{*{20}{c}}
0&{{\theta _1}}
\end{array}} \right]x(t) + \left[ {\begin{array}{*{20}{c}}
{{\theta _2}}
\end{array}} \right]u(t)\\
y(t) = \left[ {\begin{array}{*{20}{c}}
\end{array}} \right]x(t) + e(t)\\
x(0) = \left[ {\begin{array}{*{20}{c}}
{{\theta _3}}\\
\end{array}} \right]

This equation represents an electrical motor, where ${y_1}(t) = {x_1}(t)$ is the angular position of the motor shaft, and ${y_2}(t) = {x_2}(t)$ is the angular velocity. The parameter $- {\theta _1}$ is the inverse time constant of the motor, and $- {{\theta _2}}/{{\theta _1}}$ is the static gain from the input to the angular velocity.

The motor is at rest at t = 0, but its angular position ${\theta _3}$ is unknown. Suppose that the approximate nominal values of the unknown parameters are ${\theta _1} =  - 1$, ${\theta _2} = 0.25$ and ${\theta _3} = 0$. For more information about this example, see the section on state-space models in System Identification: Theory for the User , Second Edition, by Lennart Ljung, Prentice Hall PTR, 1999.

The continuous-time state-space model structure is defined by the following equation:

\dot x(t) = Fx(t) + Gu(t) + \tilde Kw(t)\\
y(t) = Hx(t) + Du(t) + w(t)\\
x(0) = x0

If you want to estimate the same model using a structured state-space representation, see Estimating Structured Continuous-Time State-Space Models.

To prepare this model for estimation:

  • Create the following file to represent the model structure in this example:
function [A,B,C,D,K,x0] = myfunc(par,T)
A = [0 1; 0 par(1)]; 
B = [0;par(2)];
C = eye(2);
D = zeros(2,1);
K = zeros(2,2);
x0 = [par(3);0];

Save the file such that it is in the MATLAB® search path.

  • Use the following syntax to define an idgrey model object based on the myfunc file:
par = [-1; 0.25; 0];
aux = {};
T = 0;
m = idgrey('myfunc',par,'c',aux,T);

where par represents a vector of all the user-defined parameters and contains their nominal (initial) values. In this example, all the scalar-valued parameters are grouped in the par vector. The scalar-valued parameters could also have been treated as independent input arguments to the ODE function myfunc. 'c' specifies that the underlying parameterization is in continuous time. aux represents optional arguments. As myfunc does not have any optional arguments, use aux = {}. T specifies the sample time; T = 0 indicates a continuous-time model.

Load the estimation data.

data = iddata(y,u,0.1);

Use greyest to estimate the grey-box parameter values:

m_est = greyest(data,m);

where data is the estimation data and m is an estimation initialization idgrey model. m_est is the estimated idgrey model.