sim(idnlarx) - Simulate nonlinear ARX model

Syntax

YS = sim(MODEL,U)
YS = sim(MODEL,U,'Noise')
YS = sim(MODEL,U,'InitialState',INIT)

Description

YS = sim(MODEL,U) simulates a dynamic system with an idnlarx model.

YS = sim(MODEL,U,'Noise') produces a noise corrupted simulation with an additive Gaussian noise scaled according to the value of the NoiseVariance property of MODEL.

YS = sim(MODEL,U,'InitialState',INIT) specifies the initial conditions for simulation using various options, such as numerical initial state vector or past I/O data.

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

Input

Input

Examples

Simulation of single-input single-output idnlarx model

In this example you simulate a single-input single-output idnlarx model M about a known equilibrium condition, with an input level of 1 and output level of 10.

  1. Load sample data.

    load iddata2;
    
  2. Estimate an idnlarx model from data.

    M = nlarx(z2, [2 2 1], 'tree'); 
  3. Estimate current states of model based on past data.

    x0 = data2state(M, struct('Input',1, 'Output', 10));
    
  4. Simulate the model using the initial states returned by data2state.

    sim(M, z2, 'init', x0);

MATLAB software responds with a plot of the simulated response.

Continuing from End of Previous Simulation

In this example you continue the simulation of a model from the end of a previous simulation run.

  1. Estimate the idnlarx model from data.

    load iddata2
    M = nlarx(z2, [2 2 1], 'tree'); % idnlarx model
  2. Simulate the model using first half of input data of z2

    u1 = z2(1:200,[]); 
    % Simulate starting from zero initial states
    ys1 = sim(M, u1, 'init', 'z');
    
  3. Start another simulation, using the same states of the model from when the first simulation ended. For the second simulation, you use the second half of the input data of z2.

    % input data for next simulation (second half of z2's input)
    u2 = z2(201:end, []);
  4. In order to set the initial states for second simulation correctly, package input u1 and output ys1 from the first simulation into one iddata object.

    firstSimData = [ys1,u1];
  5. Pass this data as initial conditions for the next simulation.

    ys2 = sim(M, u2, 'init', firstSimData); 
  6. Verify the two simulations by comparing to a complete simulation using all the input data of z2.

    uTotal = z2(:,[]); % extract the whole input data
    ysTotal = sim(M, uTotal, 'init', 'z');
    
    % Compare the values of ys1, ys2 and ysTotal. 
    % ys1 should be equal to first half of ysTotal. 
    % ys2 should be equal to the second half of ysTotal
    plot(ys1,'b', ys2, 'g', ysTotal, 'k*') % plot the three responses

    MATLAB software responds with a plot showing the three responses, with ysTotal overlaying ys1 and ys2 to verify that they match.

Matching Model Response to Output Data

In this example, you estimate initial states of model M such that the response best matches the output in data setz2.

  1. Load the sample data and create data object z2.

    load iddata2;
    z2 = z2(1:50);
    
  2. Estimate idnlarx model from data.

    M = nlarx(z2,[4 3 2],'wave'); 
  3. Estimate initial states of M to best fit z2.y in the simulated response.

    x0 = findstates(M, z2, [], 'sim'); 
    
  4. Simulate the model.

    sim(M, z2.u, 'init', x0)
    

MATLAB software responds with the following plot.

Simulation About Steady-State Condition with Known Input and Unknown Output

In this example you start simulation of a model about a steady-state condition, where the input is known to be 1, but the output is unknown.

MATLAB software responds with the following plot.

See Also

predict(idnlarx) 
findop(idnlarx) 
data2state(idnlarx) 
finstates(idnlarx) 

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS