greyest
Estimate ODE parameters of linear greybox model
Description
incorporates a sys
= greyest(data
,init_sys
,opt
)greyestOptions
option set
opt
that specifies options such as handling of initial states and
regularization options.
Examples
Estimate GreyBox Model
Estimate the parameters of a DC motor using the linear greybox framework.
Load the measured data.
load('dcmotordata'); data = iddata(y, u, 0.1, 'Name', 'DCmotor'); data.InputName = 'Voltage'; data.InputUnit = 'V'; data.OutputName = {'Angular position', 'Angular velocity'}; data.OutputUnit = {'rad', 'rad/s'}; data.Tstart = 0; data.TimeUnit = 's';
data
is an iddata
object containing the measured data for the outputs, the angular position, the angular velocity. It also contains the input, the driving voltage.
Create a greybox model representing the system dynamics.
For the DC motor, choose the angular position (rad) and the angular velocity (rad/s) as the outputs and the driving voltage (V) as the input. Set up a linear statespace structure of the following form:
$$\underset{}{\overset{\dot{}}{x}}(t)=\left[\begin{array}{cc}0& 1\\ 0& \frac{1}{\tau}\end{array}\right]x(t)+\left[\begin{array}{c}0\\ \frac{G}{\tau}\end{array}\right]u(t)$$
$$y(t)=\left[\begin{array}{cc}1& 0\\ 0& 1\end{array}\right]x(t).$$
$$\tau $$ is the time constant of the motor in seconds, and $$G$$ is the static gain from the input to the angular velocity in rad/(V*s).
G = 0.25; tau = 1; init_sys = idgrey('motorDynamics',tau,'cd',G,0);
The governing equations in statespace form are represented in the MATLAB® file motorDynamics.m
. To view the contents of this file, enter edit motorDynamics.m
at the MATLAB command prompt.
$$G$$ is a known quantity that is provided to motorDynamics.m
as an optional argument.
$$\tau $$ is a free estimation parameter.
init_sys
is an idgrey
model associated with motor.m
.
Estimate $$\tau $$.
sys = greyest(data,init_sys);
sys
is an idgrey
model containing the estimated value of $$\tau $$.
To obtain the estimated parameter values associated with sys
, use getpvec(sys)
.
Analyze the result.
opt = compareOptions('InitialCondition','zero'); compare(data,sys,Inf,opt)
sys
provides a 98.35% fit for the angular position and an 84.42% fit for the angular velocity.
Estimate GreyBox Model Using Regularization
Estimate the parameters of a DC motor by incorporating prior information about the parameters when using regularization constants.
The model is parameterized by static gain G
and time constant $$\tau $$. From prior knowledge, it is known that G
is about 4 and $$\tau $$ is about 1. Also, you have more confidence in the value of $$\tau $$ than G
and would like to guide the estimation to remain close to the initial guess.
Load estimation data.
load regularizationExampleData.mat motorData
The data contains measurements of motor's angular position and velocity at given input voltages.
Create an idgrey
model for DC motor dynamics. Use the function DCMotorODE
that represents the structure of the greybox model.
mi = idgrey(@DCMotorODE,{'G', 4; 'Tau', 1},'cd',{}, 0); mi = setpar(mi, 'label', 'default');
If you want to view the DCMotorODE
function, type:
type DCMotorODE.m
function [A,B,C,D] = DCMotorODE(G,Tau,Ts) %DCMOTORODE ODE file representing the dynamics of a DC motor parameterized %by gain G and time constant Tau. % % [A,B,C,D,K,X0] = DCMOTORODE(G,Tau,Ts) returns the state space matrices % of the DCmotor with timeconstant Tau and static gain G. The sample % time is Ts. % % This file returns continuoustime representation if input argument Ts % is zero. If Ts>0, a discretetime representation is returned. % % See also IDGREY, GREYEST. % Copyright 2013 The MathWorks, Inc. A = [0 1;0 1/Tau]; B = [0; G/Tau]; C = eye(2); D = [0;0]; if Ts>0 % Sample the model with sample time Ts s = expm([[A B]*Ts; zeros(1,3)]); A = s(1:2,1:2); B = s(1:2,3); end
Specify regularization options Lambda.
opt = greyestOptions; opt.Regularization.Lambda = 100;
Specify regularization options R.
opt.Regularization.R = [1, 1000];
You specify more weighting on the second parameter because you have more confidence in the value of $$\tau $$ than G
.
Specify the initial values of the parameters as regularization option $$\theta $$*.
opt.Regularization.Nominal = 'model';
Estimate the regularized greybox model.
sys = greyest(motorData, mi, opt);
Input Arguments
data
— Estimation data
timetable  numeric matrix pair  iddata
object  frd
object  idfrd
object
Uniformly sampled estimation data, specified as a timetable, a commaseparated matrix pair, or a timedomain or frequencydomain data object, as the following sections describe.
data
has the same input and output dimensions as
init_sys
.
By default, the software sets the sample time of the model to the sample time of the estimation data.
Timetable
Specify data
as a timetable
that uses a regularly spaced time vector.
data
contains variables representing input and output
channels.
CommaSeparated Matrix Pair
Specify data
as a commaseparated pair of numeric matrices
that contain input and output timedomain signal values. Use this
data
specification only for discretetime systems.
Data Object
Specify data as an iddata
, idfrd
, or
frd
object.
For timedomain estimation,
data
must be a timedomainiddata
object containing the input and output signal values.For frequencydomain estimation,
data
can be one of the following:
For more information about working with estimation data types, see Data Domains and Data Types in System Identification Toolbox.
opt
— Estimation options
greyestOptions
option set
Estimation options, specified as a greyestOptions
option set. Options specified by opt
include:
Handling of initial states
Regularization
Numerical search method used for estimation
Output Arguments
sys
— Identified linear greybox model
idgrey
model
Estimated greybox model, returned as an idgrey
model. This model is created using the specified initial system,
and estimation options.
Information about the estimation results and options used is stored in
the Report
property of the model.
Report
has the following fields:
Report Field  Description 

Status  Summary of the model status, which indicates whether the model was created by construction or obtained by estimation 
Method  Estimation command used 
InitialState  Handling of initial states during estimation, returned as one of the following:
This field is especially useful to view how the initial
states were handled when the 
DisturbanceModel  Handling of the disturbance component (K) during estimation, returned as one of the following values:
This field is especially useful to view the how the
disturbance component was handled when the 
Fit  Quantitative assessment of the estimation, returned as a structure. See Loss Function and Model Quality Metrics for more information on these quality metrics. The structure has these fields.

Parameters  Estimated values of model parameters 
OptionsUsed  Option set used for estimation. If no custom options were configured,
this is a set of default options. See 
RandState  State of the random number stream at the start of estimation. Empty,

DataUsed  Attributes of the data used for estimation, returned as a structure with the following fields.

Termination  Termination conditions for the iterative search used for prediction error minimization, returned as a structure with these fields.
For estimation methods that do not require numerical search
optimization, the 
For more information on using Report
, see Estimation Report.
x0
— Initial states
matrix
Initial states computed during the estimation, returned as a matrix containing a column vector corresponding to each experiment.
This array is also stored in the Parameters
field of the model
Report
property.
Version History
Introduced in R2012aR2022b: Timedomain estimation data is accepted in the form of timetables and matrices
Most estimation, validation, analysis, and utility functions now accept timedomain
input/output data in the form of a single timetable that contains both input and output data
or a pair of matrices that contain the input and output data separately. These functions
continue to accept iddata
objects as a data source as well, for
both timedomain and frequencydomain data.
R2018a: Advanced Options are deprecated for SearchOptions
when SearchMethod
is 'lsqnonlin'
Specification of lsqnonlin
 related advanced options are deprecated,
including the option to invoke parallel processing when estimating using the
lsqnonlin
search method, or solver, in Optimization Toolbox™.
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissezla dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)