メインコンテンツ

addResponse

Add dynamic system response to existing response plot

Since R2024b

    Description

    addResponse(rp,sys) adds the response for dynamic system model sys to the existing response plot associated with chart object rp.

    • The time and frequency specifications for the added response are computed automatically.

    • The line width and color for the response are assigned automatically.

    example

    addResponse(rp, sys1,sys2,...,sysN) add the responses for multiple dynamic system models.

    addResponse(___,Name=Value) configures added responses using one or more name-value arguments. For example, addResponse(rp,sys,LineWidth=1) adds the response for model sys and sets the plot line width to 1.

    When adding responses for multiple systems, the specified name-value arguments apply to all responses.

    Examples

    collapse all

    Create a second-order transfer function with a damping ratio of 0.5.

    wn = 2;
    zeta = 0.5;
    sys = tf(wn^2,[1,2*zeta*wn,wn^2]);

    Plot the step response of this system.

    sp = stepplot(sys);

    MATLAB figure

    Create a transfer function with a lower damping ratio and add it to the step plot.

    zetaL = 0.25;
    sysL = tf(wn^2,[1,2*zetaL*wn,wn^2]);
    addResponse(sp,sysL);

    MATLAB figure

    Create a transfer function with a higher damping ratio and add it to the step plot.

    zetaH = 0.75;
    sysH = tf(wn^2,[1,2*zetaH*wn,wn^2]);
    addResponse(sp,sysH);

    MATLAB figure

    Add a legend to the plot.

    legend("zeta = 0.5","zeta = 0.25","zeta = 0.75",...
        Location="southeast");

    MATLAB figure

    Input Arguments

    collapse all

    Response plot chart, specified as an object created using one of these functions:

    • impulseplot (Control System Toolbox) — Impulse response

    • initialplot (Control System Toolbox) — Initial condition response

    • stepplot (Control System Toolbox) — Step response

    • lsimplot (Control System Toolbox) — Simulated time response to arbitrary input

    • bodeplot (Control System Toolbox) — Bode frequency response

    • nicholsplot (Control System Toolbox) — Nichols frequency response

    • nyquistplot (Control System Toolbox) — Nyquist response

    • sigmaplot (Control System Toolbox) — Singular values for frequency response

    • pzplot (Control System Toolbox) — Pole-zero map

    • iopzplot (Control System Toolbox) — Plot pole-zero map for input-output pairs

    • rlocusplot (Control System Toolbox) — Root locus plot

    Dynamic system, specified as a SISO or MIMO dynamic system model or array of dynamic system models. Dynamic systems that you can use include:

    • Continuous-time or discrete-time numeric LTI models, such as tf (Control System Toolbox), zpk (Control System Toolbox), or ss (Control System Toolbox) models.

    • Sparse state-space models, such as sparss (Control System Toolbox) or mechss (Control System Toolbox) models.

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

      • For tunable control design blocks, the function evaluates the model at its current value to plot the response.

      • For uncertain control design blocks, the function plots the nominal value and random samples of the model.

    • Frequency-response data models such as frd models. For such models, the function plots the response at the frequencies defined in the model.

    • Identified LTI models, such as idtf, idss, or idproc models.

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

    Dependencies

    The supported models depend on the type of chart object specified in rp.

    • Frequency-response data models are supported only for bodeplot, nicholsplot, nyquistplot, and sigmaplot chart objects.

    • Linear time-varying and linear parameter-varying models are supported only for stepplot, impulseplot, initialplot, and lsimplot chart objects.

    • For rlocusplot chart objects, only SISO models are supported.

    Name-Value Arguments

    expand all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: addResponse(rp,sys,Color="red") adds a response and sets its color to red.

    Plot Appearance

    expand all

    Response name, specified as a string or character vector and stored as a string.

    Response visibility, specified as one of these logical on/off values:

    • "on", 1, or true — Display the response in the plot.

    • "off", 0, or false — Do not display the response in the plot.

    The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

    Option to list the response in the legend, specified as one of these logical on/off values:

    • "on", 1, or true — List the response in the legend.

    • "off", 0, or false — Do not list the response in the legend.

    The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

    Marker style, specified as one of these values. Specifying a marker style using a name-value argument overrides any marker style that you specify using LineSpec.

    MarkerDescription
    "none"No marker
    "o"Circle
    "+"Plus sign
    "*"Asterisk
    "."Point
    "x"Cross
    "_"Horizontal line
    "|"Vertical line
    "s"Square
    "d"Diamond
    "^"Upward-pointing triangle
    "v"Downward-pointing triangle
    ">"Right-pointing triangle
    "<"Left-pointing triangle
    "p"Pentagram
    "h"Hexagram

    Dependencies

    The MarkerStyle argument is not supported for pzplot or iopzplot responses.

    Plot color, specified as an RGB triplet or a hexadecimal color code and stored as an RGB triplet.

    Alternatively, you can specify some common colors by name. This table lists these colors and their corresponding RGB triplets and hexadecimal color codes.

    Color NameRGB TripletHexadecimal Color Code

    "red" or "r"

    [1 0 0]#FF0000

    "green" or "g"

    [0 1 0]#00FF00

    "blue" or "b"

    [0 0 1]#0000FF

    "cyan" or "c"

    [0 1 1]#00FFFF

    "magenta" or "m"

    [1 0 1]#FF00FF

    "yellow" or "y"

    [1 1 0]#FFFF00

    "black" or "k"

    [0 0 0]#000000

    "white" or "w"

    [1 1 1]#FFFFFF

    Line style, specified as one of these values.

    Line StyleDescription
    "-"Solid line
    "--"Dashed line
    ":"Dotted line
    "-."Dash-dotted line
    "none"No line

    Dependencies

    The LineStyle argument is not supported for pzplot or iopzplot responses.

    Marker size, specified as a positive scalar.

    Line width, specified as a positive scalar.

    Series index, specified as a positive integer or "none".

    By default, the SeriesIndex property is a number that corresponds to the order in which the response was added to the chart, starting at 1. MATLAB® uses the number to calculate indices for automatically assigning color, line style, or markers for responses. Any responses in the chart that have the same SeriesIndex number also have the same color, line style, and markers.

    A SeriesIndex value of "none" indicates that a response does not participate in the indexing scheme.

    Plot options, specified as one of the following objects, depending on the type of chart object specified in rp.

    Options ObjectChart Object rp
    timeoptions (Control System Toolbox)impulseplot, initialplot, stepplot, and lsimplot
    bodeoptions (Control System Toolbox)bodeplot
    nicholsoptions (Control System Toolbox)nicholsplot
    nyquistoptions (Control System Toolbox)nyquistplot
    sigmaoptions (Control System Toolbox)sigmapplot
    pzoptions (Control System Toolbox)pzplot, iopzplot, and rlocusplot

    Time-Domain Response

    expand all

    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 size of the time step 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.

    If you specified a step delay td using Config, the function applies the step at t = t0+td.

    Dependencies

    This argument is supported only when rp is one of the following objects:

    • stepplot

    • impulseplot

    • initialplot

    • lsimplot

    Parameter trajectory of the LPV model, specified as a matrix or a 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.

      This option is useful when you want to simulate quasi-LPV models. For an example, see Step Response of LPV Model.

    Dependencies

    This argument is supported only when sys is an LPV model and rp is a stepplot object or an impulseplot object.

    Dependencies

    This argument is supported only when rp is one of the following objects:

    • stepplot

    • impulseplot

    • initialplot

    • lsimplot

    Configuration of the applied signal, specified as a RespConfig object. By default, step applies an input that goes from 0 to 1 at time t = 0. Use this input argument to change the configuration of the step input. See Response to Custom Step Input for an example.

    For lpvss (Control System Toolbox) and ltvss (Control System Toolbox) models with offsets (x0(t),u0(t)), you can use RespConfig to define the input relative to u0(t,p) and initialize the simulation with the state x0(t,p).

    This argument is supported only when rp is a stepplot object or an impulse object.

    Dependencies

    This argument is supported only when rp is a stepplot object or an impulseplot object.

    Initial conditions for simulating a state-space model, specified as one these values. Specifying initial conditions using a name-value argument overrides the initial conditions that you specify using IC.

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

    • Response configuration, specified as a RespConfig (Control System Toolbox) object.

    • Operating condition, specified as an operating point object created using findop (Control System Toolbox). An operating point object allows you to start the simulation from a steady-state operating condition with nonzero past u, w, and y values. For example, to start a simulation from nonzero y value, you can specify:

      op = findop(sys,y=3);
      y = lsim(sys,u,t,op)

    If you do not specify an initial condition, then the simulation starts from an all-zero initial condition.

    Dependencies

    This argument is supported only when rp is an initialplot object or an lsimplot object.

    Discretization interpolation method for sampling continuous-time models, specified as one of the following.

    • "zoh" — Zero-order hold

    • "foh" — First-order hold

    When sys is a continuous-time model, lsimplot computes the time response by discretizing the model using a sample time equal to the time step dT = t(2)-t(1) of t. If you do not specify a discretization method, then lsimplot selects the method automatically based on the smoothness of the signal u. For more information about these two discretization methods, see Continuous-Discrete Conversion Methods (Control System Toolbox).

    Dependencies

    This argument is supported only when rp is an lsimplot object.

    Frequency-Domain Response

    expand all

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

    • Cell array of the form {wmin,wmax} — Compute the response at frequencies in the range from wmin to wmax. If wmax is greater than the Nyquist frequency of sys, the response is computed only up to the Nyquist frequency.

    • Vector of frequencies — Compute the response at each specified frequency. For example, use logspace to generate a row vector with logarithmically spaced frequency values. The vector w can contain both positive and negative frequencies.

    • [] — Automatically select frequencies based on system dynamics.

    For models with complex coefficients, if you specify a frequency range of [wmin,wmax] for your plot, then in:

    • Log frequency scale, the plot frequency limits are set to [wmin,wmax] and the plot shows two branches, one for positive frequencies [wmin,wmax] and one for negative frequencies [–wmax,–wmin].

    • Linear frequency scale, the plot frequency limits are set to [–wmax,wmax] and the plot shows a single branch with a symmetric frequency range centered at a frequency value of zero.

    Specify frequencies in units of rad/TimeUnit, where TimeUnit is the TimeUnit property of the model.

    Dependencies

    This argument is supported only when rp is a bodeplot,nicholsplot, nyquistplot, or sigmaplot object.

    Type of modified singular values to plot, specified as one of the following values.

    • 1 — Plot the singular values of the frequency response H-1, where H is the frequency response of sys.

    • 2 — Plot the singular values of the frequency response I+H.

    • 3 — Plot the singular values of the frequency response I+H-1.

    Dependencies

    • This argument is supported only when rp is a sigmaplot object.

    • You can specify SingularValueType only when sys has the same number of inputs and outputs.

    Root Locus Plot

    expand all

    Feedback gain values that pertain to pole locations, specified as a vector. The feedback gains define the trajectory of the poles thereby affecting the shape of the root locus plot.

    Dependencies

    This argument is supported only when rp is an rlocusplot object.

    Version History

    Introduced in R2024b

    See Also

    (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox) | (Control System Toolbox)