Beruflich Dokumente
Kultur Dokumente
http://www.mathworks.com/products/sysid/demos.html?file=/products/demos/shipping/ident/idnlgreydemo1.html
This example shows how to construct, estimate and analyze nonlinear grey-box models.
Nonlinear grey-box (idnlgrey) models are suitable for estimating parameters of systems that are described by nonlinear state-space structures in continuous or discrete time. You can use both idgrey (linear grey-box model) and idnlgrey objects to model linear systems. However, you can only use idnlgrey to represent nonlinear dynamics. To learn about linear grey-box modeling using idgrey, see "Building Structured and User-Defined Models Using System Identification Toolbox".
Contents
About the Model About the Input-Output Data Linear Modeling of the DC-Motor Performance Evaluation of the Initial DC-Motor Model Parameter Estimation Performance Evaluation of the Estimated DC-Motor Model Conclusions
If you ignore the disturbances and choose y(1) as the angular position [rad] and y(2) as the angular velocity [rad/s] of the motor, you can set up a linear state-space structure of the following form (see Ljung, L. System Identification: Theory for the User, Upper Saddle River, NJ, Prentice-Hall PTR, 1999, 2nd ed., p. 95-97 for the derivation):
| 0
| | u(t)
-- x(t) = | dt | 0 | 1 y(t) = | | 0
| k/tau |
tau is the time-constant of the motor in [s] and k is the static gain from the input to the angular velocity in [rad/(V*s)]
. See Ljung (1999) for how tau and k relate to the physical parameters of the motor.
set(z, 'InputName', 'Voltage', 'InputUnit', 'V'); set(z, 'OutputName', {'Angular position', 'Angular velocity'}); set(z, 'OutputUnit', {'rad', 'rad/s'}); set(z, 'Tstart', 0, 'TimeUnit', 's');
4. Plot the data.
figure('Name', [z.Name ': Voltage input -> Angular velocity output']); plot(z(:, 2, 1)); elocity). % Plot second input-output pair (Voltage -> Angular v
In this example, you use a MATLAB file, but you can also use C MEX-files (to gain computational speed), P-files or function handles. For more information, see Creating IDNLGREY Model Files".
function [dx, y] = dcmotor_m(t, x, u, tau, k, varargin) % Output equations. y = [x(1); x(2) ]; % State equations. dx = [x(2); -(1/tau)*x(2)+(k/tau)*u(1) ];
The file must always be structured to return the following:
Output arguments:
The first three input arguments must be: t (time), x (state vector, [] for static systems), u (input vector, [] for timeseries). Ordered list of parameters follow. The parameters can be scalars, column vectors, or 2-dimensional matrices.
The model describes how the inputs generate the outputs using the state equation(s).
% File describing the model structure. % Model orders [ny nu nx]. % Initial parameters. Np = 2.
...
'OutputName', {'Angular position', 'Angular velocity'}, ... 'OutputUnit', {'rad', 'rad/s'}, 'TimeUnit', 's');
4. Specify names and units of the initial states and parameters.
...
setinit(nlgr, 'Name', {'Angular position' 'Angular velocity'}); setinit(nlgr, 'Unit', {'rad' 'rad/s'}); setpar(nlgr, 'Name', {'Time-constant' 'Static gain'}); setpar(nlgr, 'Unit', {'s' 'rad/(V*s)'});
You can also use setinit and setpar to assign values, minima, maxima, and estimation status for all initial states or parameters simultaneously.
size(nlgr) Nonlinear state space model with 2 outputs, 1 input, 2 states, and 2 paramet
ers (2 free).
b. View the initial states and parameters.
Both the initial states and parameters are structure arrays. The fields specify the properties of an individual initial state or parameter. Type idprops idnlgrey InitialStates and idprops idnlgrey Parameters for more information.
Name: 'Angular position' Unit: 'rad' Value: 0 Minimum: -Inf Maximum: Inf Fixed: 1
ans =
Name: 'Static gain' Unit: 'rad/(V*s)' Value: 0.2800 Minimum: -Inf Maximum: Inf Fixed: 0
c. Retrieve information for all initial states or model parameters in one call.
For example, obtain information on initial states that are fixed (not estimated) and the minima of all model parameters.
[1] [1]
ans =
[-Inf] [-Inf]
dx/dt = F(t, u(t), x(t), p1, p2) y(t) = H(t, u(t), x(t), p1, p2) + e(t)
Use get to obtain more information about the model properties. The idnlgrey object shares many properties of parametric linear model objects.
get(nlgr) Name: 'DC-motor' Ts: 0 TimeUnit: 's' TimeVariable: 't' InputName: {'Voltage'} InputUnit: {'V'} OutputName: {2x1 cell} OutputUnit: {2x1 cell} FileName: 'dcmotor_m' Order: [1x1 struct] Parameters: [2x1 struct] InitialStates: [2x1 struct] FileArgument: {} CovarianceMatrix: 'Estimate' NoiseVariance: [2x2 double] Algorithm: [1x1 struct] EstimationInfo: [1x1 struct] Notes: {} UserData: [] Performance Evaluation of the Initial DC-Motor Model
Before estimating the parameters tau and k, simulate the output of the system with the parameter guesses using the default differential equation solver (a Runge-Kutta 45 solver with adaptive step length adjustment).
1. Set the absolute and relative error tolerances to small values (1e-6 and 1e-5, respectively).
compare displays both measured and simulated outputs of one or more models, whereas predict, called with
the same input arguments, displays the simulated outputs.
Figure 3: Comparison between measured outputs and the simulated outputs of the initial DC-motor model.
Parameter Estimation
Estimate the parameters and initial states using pem (Prediction-Error identification Method).
nlgr = pem(z, nlgr, 'Display', 'Full'); Criterion: Trace minimization Scheme: Nonlinear least squares with automatically chosen line search met hod ----------------------------------------------------------------------------------------Norm of Iteration Bisections ----------------------------------------------------------------------------------------0 1 0 2 0 3 0 4 0 ----------------------------------------------------------------------------------------Performance Evaluation of the Estimated DC-Motor Model
1. Review the information about the estimation process.
First-order optimality
Cost
step
2.78714
5.06e+003
75.6
0.223389
0.827
1.89e+003
75.6
92
0.119343
0.106
44.4
45.7
46.6
0.118707
0.0124
0.67
0.527
0.533
0.118707
0.000834
0.00891
0.000195
0.000198
This information is stored in the EstimationInfo property of the idnlgrey object. The property also contains information about how the model was estimated, such as solver and search method, data set, and why the estimation was terminated.
nlgr.EstimationInfo ans =
Status: 'Estimated model (PEM)' Method: 'Solver: ode45; Search: gn, lm, gna, grad' LossFcn: 0.0011 FPE: 0.0011 DataName: 'DC-motor' DataLength: 400 DataTs: {[0.1000]} DataDomain: 'Time' DataInterSample: {'zoh'} WhyStop: 'Near (local) minimum, (norm(g) < tol).' UpdateNorm: 1.9799e-004 LastImprovement: 1.9799e-004 Iterations: 4 InitialGuess: [1x1 struct] Warning: '' EstimationTime: 9.2665
The fits are 98% and 84%, which indicate that the estimated model captures the dynamics of the DC motor well.
figure;
compare(z, nlgr);
Figure 4: Comparison between measured outputs and the simulated outputs of the estimated IDNLGREY DC-motor model.
3. Compare the performance of the idnlgrey model with a second-order ARX model.
dcarx = arx(z, 'na', [2 2; 2 2], 'nb', [2; 2], 'nk', [1; 1]); figure; compare(z, nlgr, dcarx);
Figure 5: Comparison between measured outputs and the simulated outputs of the estimated IDNLGREY and ARX DC-motor models.
The prediction errors obtained are small and are centered around zero (non-biased).
Figure 6: Prediction errors obtained with the estimated IDNLGREY DC-motor model.
Residuals indicate what is left unexplained by the model and are small for good model quality. Execute the following two lines of code to generate the residual plot. Press any key to advance from one plot to another.
A unit input step results in an angular position showing a ramp-type behavior and to an angular velocity that stabilizes at a constant level.
You can assess the quality of the estimated model to some extent by looking at the estimated covariance matrix and the estimated noise variance. A "small" value of the (i, i) diagonal element of the covariance matrix indicates that the i:th model parameter is important for explaining the system dynamics when using the chosen model structure. Small noise variance (covariance for multi-output systems) elements are also a good indication that the model captures the estimation data in a good way.
1.0e-004 *
0.1521
0.0015
0.0015
0.0007
ans =
0.0099 -0.0004
-0.0004 0.1094
For more information about the estimated model, use present to display the initial states and estimated parameter values, and estimated uncertainty (standard deviation) for the parameters.
dx/dt = F(t, u(t), x(t), p1, p2) y(t) = H(t, u(t), x(t), p1, p2) + e(t)
Input: u(1) States: x(1) nf, Inf] x(2) nf, Inf] Angular velocity(t) [rad/s] xinit@exp1 -0.133728 (est) in [-I Angular position(t) [rad] Voltage(t) [V] initial value xinit@exp1 0.0302986 (est) in [-I
Outputs: y(1) y(2) Angular position(t) [rad] Angular velocity(t) [rad/s] value 0.243646 standard dev 0.00390033 (est) in [-Inf, In
0.249645
0.00027217
(est) in [-Inf, In
The model was estimated from the data set 'DC-motor', which contains 400 data samples. Loss function 0.00107462 and Akaike's FPE 0.00108536
Created:
09-Jul-2011 07:31:06
Using nonlinear grey-box models in more advanced modeling situations, such as building nonlinear continuous- and discrete-time, time-series and static models. Writing and using C MEX model-files. Handling nonscalar parameters. Impact of certain algorithm choices. For more information on identification of dynamic systems with System Identification Toolbox, visit the System Identification Toolbox product information page.