# initial

System response to initial states of state-space model

## Description

For state-space and sparse state-space models, initial computes the unforced system response y to initial states xinit.

• Continuous time:

$\begin{array}{cc}\stackrel{˙}{x}=d{x}_{0}+A\left(x-{x}_{0}\right),& x\left({t}_{0}\right)={x}_{init}\\ y={y}_{0}+C\left(x-{x}_{0}\right)& \end{array}$

• Discrete time:

$\begin{array}{cc}x\left[k+1\right]=d{x}_{0}+A\left(x\left[k\right]-{x}_{0}\right)& x\left[{k}_{0}\right]={x}_{init}\\ y={y}_{0}+C\left(x\left[k\right]-{x}_{0}\right)& \end{array}$

This is the system response when u(t) is maintained at the offset value u0.

For linear time-varying or linear parameter-varying state-space models, initial computes the response with initial state xinit, initial parameters pinit (LPV models), and input held to the offset value (u(t) = u0(t) or u(t) = u0(t,p), which corresponds to the initial condition response of the local linear dynamics.

[y,tOut] = initial(sys,IC) computes the unforced initial response y of dynamic system sys from initial condition IC. The time vector tOut is in the time units of sys. initial automatically determines the time steps and duration of the simulation based on the system dynamics.

[y,tOut] = initial(sys,IC,t) simulates the response for the time steps specified by t. To define the time steps, you can specify the:

• The final simulation time using a scalar value.

• The initial and final simulation times using a two-element vector. (since R2023b)

• All the time steps using a vector.

example

[y,tOut] = initial(sys,IC,t,p) specifies the parameter trajectory p for LPV models. (since R2023a)

example

[y,tOut,x] = initial(___) returns the state trajectories x.

example

[y,tOut,x,pOut] = initial(sys,IC,t,p) returns parameter trajectories pOut when sys is an LPV model. (since R2023a)

initial(___) plots the initial condition response of sys with default plotting options for all of the previous input argument combinations. For more plot customization options, use initialplot.

• To plot responses for multiple dynamic systems on the same plot, you can specify sys as a comma-separated list of models. For example, initial(sys1,sys2,sys3) plots the responses for three models on the same plot.

• To specify a color, line style, and marker for each system in the plot, specify a LineSpec value for each system. For example, initial(sys1,LineSpec1,sys2,LineSpec2) plots two models and specifies their plot style. For more information on specifying a LineSpec value, see initialplot.

## Examples

collapse all

For this example, generate a random state-space model with 5 states and create the plot for the system response to the initial states.

rng("default")
x0 = [1,2,3,4,5];
initial(sys,x0)

Plot the response of the following state-space model:

$\begin{array}{rcl}\left[\begin{array}{l}{\underset{}{\overset{˙}{x}}}_{1}\\ {\underset{}{\overset{˙}{x}}}_{2}\end{array}\right]& =& \left[\begin{array}{cc}-0.5572& -0.7814\\ 0.7814& 0\end{array}\right]\left[\begin{array}{l}{x}_{1}\\ {x}_{2}\end{array}\right]\\ y& =& \left[\begin{array}{cc}1.9691& 6.4493\end{array}\right]\left[\begin{array}{l}{x}_{1}\\ {x}_{2}\end{array}\right].\end{array}$

Take the following initial condition:

$x\left(0\right)=\left[\begin{array}{l}1\\ 0\end{array}\right].$

a = [-0.5572, -0.7814; 0.7814, 0];
c = [1.9691  6.4493];
x0 = [1 ; 0];

sys = ss(a,[],c,[]);
initial(sys,x0)

Consider the following two-input, two-output dynamic system.

$sys\left(s\right)=\left[\begin{array}{cc}0& \frac{3s}{{s}^{2}+s+10}\\ \frac{s+1}{s+5}& \frac{2}{s+6}\end{array}\right].$

Convert the sys to state-space form since initial condition response plots are supported only for state-space models.

sys = ss([0, tf([3 0],[1 1 10]) ; tf([1 1],[1 5]), tf(2,[1 6])]);
size(sys)
State-space model with 2 outputs, 2 inputs, and 4 states.

The resultant state-space model has four states. Hence, provide an initial condition vector with four elements.

x0 = [0.3,0.25,1,4];

Create the initial condition response plot.

initial(sys,x0);

The resultant plot contains two subplots - one for each output in sys.

For this example, examine the initial condition response of the following zero-pole-gain model and limit the plot to tFinal = 15 s.

First, convert the zpk model to an ss model since initial only supports state-space models.

sys = ss(zpk(-1,[-0.2+3j,-0.2-3j],1)*tf([1 1],[1 0.05]));
tFinal = 15;
x0 = [4,2,3];

Now, create the initial conditions response plot.

initial(sys,x0,tFinal);

For this example, plot the initial condition responses of three dynamic systems.

First, create the three models and provide the initial conditions. All the models should have the same number of states.

rng('default');
x0 = [1,1,1,1];

Plot the initial condition responses of the three models using time vector t that spans 5 seconds.

t = 0:0.1:5;
initial(sys1,'r--',sys2,'b',sys3,'g-.',x0,t)

Extract the initial condition response data of the following state-space model with two states:

$\begin{array}{rcl}\left[\begin{array}{l}{\underset{}{\overset{˙}{x}}}_{1}\\ {\underset{}{\overset{˙}{x}}}_{2}\end{array}\right]& =& \left[\begin{array}{cc}-0.5572& -0.7814\\ 0.7814& 0\end{array}\right]\left[\begin{array}{l}{x}_{1}\\ {x}_{2}\end{array}\right]\\ y& =& \left[\begin{array}{cc}1.9691& 6.4493\end{array}\right]\left[\begin{array}{l}{x}_{1}\\ {x}_{2}\end{array}\right].\end{array}$

Use the following initial conditions:

$x\left(0\right)=\left[\begin{array}{l}1\\ 0\end{array}\right].$

a = [-0.5572, -0.7814; 0.7814, 0];
c = [1.9691  6.4493];
x0 = [1 ; 0];
sys = ss(a,[],c,[]);
[y,tOut,x] = initial(sys,x0);

The array y has as many rows as time samples (length of tOut) and as many columns as outputs. Similarly, x has rows equal to the number of time samples (length of tOut) and as many columns as states.

For this example, extract the initial condition response data of a state-space model with 6 states, 3 outputs and 2 inputs.

First, create the model and provide the initial conditions.

rng('default');
x0 = [0.1,0.3,0.05,0.4,0.75,1];

Extract the initial condition responses of the model using time vector t that spans 15 seconds.

t = 0:0.1:15;
[y,tOut,x] = initial(sys,x0,t);

The array y has as many rows as time samples (length of tOut) and as many columns as outputs. Similarly, x has rows equal to the number of time samples (length of tOut) and as many columns as states.

For this example, throttleLPV.m that defines the dynamics of a nonlinear engine throttle which behaves linearly in the 15 degrees to 90 degrees opening range.

Use lpvss to create the model. This model is parameterized by the throttle angle, which is the first state of the model.

c0 = 50;
k0 = 120;
K0 = 1e4;
b0 = 4e4;
yf = 15*K0/(k0+K0);
Ts = 0;
sys = lpvss("x1",@(t,p) throttleLPV(p,c0,k0,b0,K0),Ts,0,15);

You can compute the initial response for this model along a trajectory $\mathit{p}\left(\mathit{t}\right)$.

Compute the response when you start at the lower end of linear range with a small angular velocity. Specify the parameter trajectory and find the initial condition using findop.

pFcn = @(t,x,u)x(1);
xinit = [15;10];
pinit = xinit(1);
t = linspace(0,0.6,500);
ic = findop(sys,t(1),pinit,x=xinit);
y = initial(sys,ic,t,pFcn);
plot(t,y)

Compute the response when you start at the lower end of linear range with enough angular velocity to hit the upper end of this range.

xinit2 = [15;5e3];
pinit2 = xinit2(1);
t2 = linspace(0,1,1000);
ic2 = findop(sys,t2(1),pinit2,x=xinit2);
y2 = initial(sys,ic2,t2,pFcn);
plot(t2,y2)

View the data function.

type throttleLPV.m
function [A,B,C,D,E,dx0,x0,u0,y0,Delays] = throttleLPV(x1,c,k,b,K)
% LPV representation of engine throttle dynamics.
% Ref: https://www.mathworks.com/help/sldo/ug/estimate-model-parameter-values-gui.html
% x1: scheduling parameter (throttle angle; first state of the model)
% c,k,b,K: physical parameters

A = [0 1; -k -c];
B = [0; b];
C = [1 0];
D = 0;
E = [];
Delays = [];
x0 = [];
u0 = [];
y0 = [];

% Nonlinear displacement value
NLx = max(90,x1(1))-90+min(x1(1),15)-15;
% Capture the nonlinear contribution as a state-derivative offset
dx0 = [0;-K*NLx];

## Input Arguments

collapse all

Dynamic system, specified as a SISO or MIMO dynamic system model or array of dynamic system models. You can only use state-space models of the following types:

• Continuous-time or discrete-time numeric ss models.

• Generalized or uncertain LTI models such as genss or uss models. (Using uncertain models requires Robust Control Toolbox™ software.)

• For tunable control design blocks, the function evaluates the model at its current value for both plotting and returning response data.

• For uncertain control design blocks, the function plots the nominal value and random samples of the model. When you use output arguments, the function returns response data for the nominal model only.

• Sparse state-space models such as sparss and mechss models. You must specify final time tFinal for sparse state-space models.

• Linear time-varying (ltvss) and linear parameter-varying (lpvss) models.

If sys is an array of models, the function plots the responses of all models in the array on the same axes.

Time steps at which to compute the response, specified as one of the following:

• Positive scalar tFinal— Compute the response from t = 0 to t = tFinal.

• Two-element vector [t0 tFinal] — Compute the response from t = t0 to t = tFinal. (since R2023b)

• Vector Ti:dt:Tf— Compute the response for the time points specified in t.

• For continuous-time systems, dt is the sample time of a discrete approximation to the continuous system.

• For discrete-time systems with a specified sample time, dt must match the sample time property Ts of sys.

• For discrete-time systems with an unspecified sample time (Ts = -1), dt must be 1.

• [] — Automatically select time values based on system dynamics.

When you specify a time range using either tFinal or [t0 tFinal]:

• For continuous-time systems, the function automatically determines the step size and number of points based on the system dynamics.

• For discrete-time systems with a specified sample time, the function uses the sample time of sys as the step size.

• For discrete-time systems with unspecified sample time (Ts = -1), the function interprets tFinal as the number of sampling periods to simulate with a sample time of 1 second.

Express t using the time units specified in the TimeUnit property of sys.

Initial condition, specified as one of the following:

• Initial state values, specified as a vector xinit with length equal to the number of states.

• Response configuration, specified as a RespConfig object. Use this object to specify initial state and parameter values for LPV models. (since R2024b)

• Operating condition, specified as an object created using findop. (since R2024b)

Since R2023a

Parameter trajectory of the LPV model, specified as a matrix or function handle.

• For exogenous or explicit trajectories, specify p as a matrix with dimensions N-by-Np, where N is the number of time samples and Np is the number of parameters.

Thus, the row vector p(i,:) contains the parameter values at the ith time step.

• For endogenous or implicit trajectories, specify p as a function handle of the form p = F(t,x,u) in continuous time and p = F(k,x,u) in discrete time that gives parameters as a function of time t or time sample k, state x, and input u. An initial parameter value is required for this input method. To specify initial conditions, use the IC argument.

## Output Arguments

collapse all

Response data, returned as an array.

• For SISO systems, y is a column vector of the same length as t (if provided) or tOut (if you do not provide t).

• For single-input, multi-output systems, y is a matrix with as many rows as there are time samples and as many columns as there are outputs. Thus, the jth column of y, or y(:,j), contains the response of from the input to the jth output.

• For MIMO systems, the dimensions of y are then N-by-Ny, where:

• N is the number of time samples.

• Ny is the number of system outputs.

Times at which response is computed, returned as a vector. When you do not provide a specific vector t of times, initial chooses this time vector based on the system dynamics. The times are expressed in the time units of sys.

State trajectories, returned as an array. x contains the evolution of the states of sys at each time in t or tOut. The dimensions of x are N-by-Nx, where:

• N is the number of time samples.

• Nx is the number of states.

Since R2023a

Parameter trajectories, returned as an array. When sys is a linear-parameter varying (lpvss) model, pOut contains the evolution of the parameters of sys. The dimensions of pOut are N-by-Np, where:

• N is the number of time samples.

• Np is the number of parameters.

## Version History

Introduced before R2006a

expand all