Documentation Center

  • Trials
  • Product Updates

sim(idnlgrey)

Simulate nonlinear ODE model

Syntax

YS = sim(NLSYS,DATA)
YS = sim(NLSYS,DATA,'Noise');
YS = sim(NLSYS,DATA,X0INIT);
YS = sim(NLSYS,DATA,'Noise',XOINIT);
YS = sim(NLSYS,DATA,'Noise','InitialState',X0INIT);
[YS, YSD, XFINAL] = sim(NLSYS,DATA,'Noise','InitialState',X0INIT);

Description

YS = sim(NLSYS,DATA) simulates the output of an idnlgrey model.

YS = sim(NLSYS,DATA,'Noise'); simulates the model with Gaussian noise added to YS.

YS = sim(NLSYS,DATA,X0INIT); simulates the model with the specified initial states.

YS = sim(NLSYS,DATA,'Noise',XOINIT); simulates the model with the specified initial states and with Gaussian noise added.

YS = sim(NLSYS,DATA,'Noise','InitialState',X0INIT); simulates the model with the specified initial states.

[YS, YSD, XFINAL] = sim(NLSYS,DATA,'Noise','InitialState',X0INIT); performs simulation starting with the specified initial states and with Gaussian noise added, and returns the final states of the model after the simulation is completed.

To simulate the model with user-defined noise, set the input DATA = [UIN E], where UIN is the input signal and E is the noise signal. UIN and E must both be one of the following:

  • iddata objects: E stores the noise signals as inputs, where the number of inputs matches the number of model outputs.

  • Matrices: E has as many columns as there are noise signals, corresponding to the number of model outputs.

Input Arguments

  • NLSYS: idnlgrey model object.

  • DATA: Input-noise data [U E]. If E is omitted and 'Noise' is not given as an input argument, then a noise-free simulation is obtained. If E is omitted and 'Noise' is given as an input argument, then Gaussian noise created by randn(size(YS))*sqrtm(NLSYS.NoiseVariance) will be added to YS. If both E and 'Noise' are given, then E specifies the noise to add to YS. For time-continuous idnlgrey objects, DATA passed as a matrix will lead to that the data sample interval, Ts, is set to one.

  • X0INIT: Initial states. Can have the following values:

    • 'zero' : Zero initial state x(0) with all states fixed (nlsys.InitialStates.Fixed is thus ignored).

    • 'fixed' (default): Struct array (NLSYS.InitialState) determines the values of the model initial states and all states are fixed. (NLSYS.InitialStates.Fixed is ignored). Same as 'model'.

    • vector/matrix: Column vector of initial state values. For multiple experiment DATA, X0INIT may be a matrix whose columns give different initial states for each experiment. All initial states are kept fixed (nlsys.InitialStates.Fixed is thus ignored).

    • struct array : Nx-by-1 structure array with fields:

      • Name: Name of the state (a string).

      • Unit: Unit of the state (a string).

      • Value: Value of the states (a finite real 1-by-Ne vector, where Ne is the number of experiments.)

      • Minimum: Minimum values of the states (a real 1-by-Ne vector or a real scalar, in which case all initial states have the same minimum value).

      • Maximum: Maximum values of the states (a real 1-by-Ne vector or a real scalar, in which case all initial states have the same maximum value).

      • Fixed: True (or a 1-by-Ne vector of True values). Any false value is ignored.

Output Arguments

  • YS: Simulated output. If DATA is an iddata object, then YS will also be an iddata object. Otherwise, YS will be a matrix where the k:th output is found in the k:th column of YS. If DATA is a multiple-experiment iddata object, then YS will be a multiple experiment object as well.

  • YSD: Empty vector ([].) In the future, it will contain the estimated standard deviation of the simulated output.

  • XFINAL: Final states computed. In the single experiment case it is a column vector of length Nx. For multi-experiment data, XFINAL is an Nx-by-Ne matrix with the ith column specifying the initial state of experiment i.

    Note:   If sim is called without an output argument, MATLAB® software displays the simulated output(s) in a plot window.

Examples

In this example you simulate an idnlgrey model for a data set z. This example uses the nlgr model created in idnlgreydemo2.

  1. Load the data set and create an idnlgrey model.

    load twotankdata;
    
  2. Estimate the idnlgrey model.

    % Specify file.
    FileName = 'twotanks_c';
    % Specify model orders [ny nu nx].
    Order = [1 1 2];
    % Specify initial parameters.
    Parameters = {0.5; 0.0035; 0.019; ...
                  9.81; 0.25; 0.016};
    % Specify initial states.
    InitialStates = [0; 0.1];
    Ts = 0;
    nlgr = idnlgrey(FileName, Order, Parameters, ...
                    InitialStates, Ts, ...
                    'Name', 'Two tanks');
    
  3. Create an iddata object z from data z (from twotankdata.mat).

    z = iddata([], u, 0.2, 'Name', 'Two tanks');
  4. Simulate the model using the input signal from the data z.

    sim(nlgr,z)

See Also

| | |

Was this topic helpful?