Table Of Contents

modelicares.linres

Load, analyze, and plot the result of linearizing a Modelica model.

This module relies on python-control, which is included in the distribution.

class modelicares.linres.LinRes(fname='dslin.mat')

Bases: object

Class for Modelica-based linearization results and methods to analyze those results

On initialization, load and preprocess a linearized Modelica model (MATLAB® format). The model is in state space:

der(x) = A*x + B*u;
     y = C*x + D*u;

The linear system is stored as sys within this class. It is an instance of control.StateSpace, which emulates the structure of a continuous-time model in MATLAB® (e.g., the output of ss() in MATLAB®). It contains:

  • A, B, C, D: Matrices of the linear system
  • stateName: List of name(s) of the states (x)
  • inputName: List of name(s) of the inputs (u)
  • outputName: List of name(s) of the outputs (y)

Arguments:

  • fname: Name of the file (may include the path)

    The file extension (‘.mat’) is optional. The file must contain four matrices: Aclass (specifies the class name, which must be “AlinearSystem”), nx, xuyName, and ABCD.

Example:

>>> from modelicares import LinRes
>>> lin = LinRes('examples/PID')
__repr__()

Return a formal description of the LinRes instance.

Example:

>>> from modelicares import LinRes
>>> lin = LinRes('examples/PID.mat')
>>> lin 
LinRes('...PID.mat')
__str__()

Return an informal description of the LinRes instance.

Example:

>>> from modelicares import LinRes
>>> lin = LinRes('examples/PID.mat')
>>> print(lin) 
Modelica linearization results from "...PID.mat"
bode(ax=None, pairs=None, w_min=-1, w_max=3, label='bode', title=None, colors=['b', 'g', 'r', 'c', 'm', 'y', 'k'], styles=[(100, 0), (3, 3), (1, 1), (3, 2, 1, 2)], **kwargs)

Create a Bode plot of the system’s response.

Arguments:

  • ax: Axis onto which the data should be plotted.

    If not provided, an axis will be created (in a new figure).

  • pairs: List of (input index, output index) tuples of each transfer function to be evaluated

    If not provided, all of the transfer functions will be plotted.

  • w_min: Common logarithm of the minimum angular frequency

  • w_max: Common logarithm of the maximum angular frequency

  • label: Label for the figure (ignored if ax is provided)

    This will be used as the base filename if the figure is saved.

  • title: Title for the figure

    If title is None (default), then the title will be “Bode Plot of fbase”, where fbase is the base filename of the data. Use ‘’ for no title.

  • colors: Color or list of colors that will be used sequentially

    Each may be a character, grayscale, or rgb value.

  • styles: Line/dash style or list of line/dash styles that will be used sequentially

    Each style is a string representing a linestyle (e.g., “–”) or a tuple of on/off lengths representing dashes. Use “” for no line and “-” for a solid line.

  • **kwargs: Propagated to control.matlab.bode()

The Bode plots of a MIMO system are overlayed. This is different than MATLAB®, which creates an array of subplots.

Example:

>>> from modelicares import LinRes, saveall

>>> lin = LinRes('examples/PID.mat')
>>> lin.bode(label='examples/PID-bode',
...          title="Bode Plot of Modelica.Blocks.Continuous.PID")
>>> saveall()
Saved examples/PID-bode.pdf
Saved examples/PID-bode.png
Saved examples/PID-bode.pdf
Saved examples/PID-bode.png
example for LinRes.bode()
nyquist(ax=None, pairs=None, w_min=0.79817986835811505, w_max=2.7981798683581149, label='nyquist', title=None, xlabel='Real Axis', ylabel='Imaginary Axis', mark=True, colors=['b', 'g', 'r', 'c', 'm', 'y', 'k'], **kwargs)

Create a Nyquist plot of the system’s response.

Arguments:

  • ax: Axis onto which the data should be plotted.

    If not provided, an axis will be created (in a new figure).

  • pairs: List of (input index, output index) tuples of each transfer function to be evaluated

    If not provided, all of the transfer functions will be plotted.

  • w_min: Common logarithm of the minimum angular frequency

  • w_max: Common logarithm of the maximum angular frequency

  • label: Label for the figure (ignored if ax is provided)

    This will be used as the base filename if the figure is saved.

  • title: Title for the figure

    If title is None (default), then the title will be “Nyquist Plot of fbase”, where fbase is the base filename of the data. Use ‘’ for no title.

  • xlabel: x-axis label

  • ylabel: y-axis label

  • mark: True if frequencies should be labeled (with a dot and text denoting the frequency)

  • colors: Color or list of colors that will be used sequentially

    Each may be a character, grayscale, or rgb value.

  • **kwargs: Propagated to control.matlab.nyquist() and control.matlab.nyquist_label()

The Nyquist plots of a MIMO system are overlayed. This is different than MATLAB®, which creates an array of subplots.

Example:

>>> from modelicares import LinRes, saveall

>>> lin = LinRes('examples/PID.mat')
>>> lin.nyquist(label='examples/PID-nyquist',
...             title="Nyquist Plot of Modelica.Blocks.Continuous.PID")
>>> saveall()
Saved examples/PID-nyquist.pdf
Saved examples/PID-nyquist.png
example for LinRes.nyquist()