LinearAnalysis package

Requirements.LinearAnalysis  ยท source

Icon of LinearAnalysis

Eigenvalue predicates over the state matrix of a linearization, or over a mode table, read from a file

Extends Modelica.Icons.Package

Requirements on the eigenvalues of a linearized plant: stability margins, damping, natural frequencies, time constants, pole regions. A linearization is a tool operation, not a simulation, so no check model can compute a plant's eigenvalues inside the run that produces them. The workflow therefore has two steps:

  1. Linearize the plant at its operating point in your Modelica tool (or on its FMU) and write the state matrix A to a MATLAB v4 file.
  2. Check it in a small Modelica model: readStateMatrix reads the matrix, modes takes its eigenvalues (LAPACK's dgeev, as Modelica.Math.Matrices.eigenValues does) and folds them into modes, and the blocks evaluate the predicates as constants over a short nominal run: EigenvalueCheck (a real-part, damping, frequency or time-constant bound over every mode, optionally in a frequency band) and EigenvaluesWithinRegion (a polygon of the (Re, Im) plane), each with Property and margin outputs. Connect them to Verify.Requirement blocks and a PrintViolations as in any other check model.

Step 1: linearizing in different tools

Linearization is available in every Modelica tool, but it is not standardized: the command, the operating point it linearizes at, the state selection and the output format all differ. This library does not depend on any of them; it only needs a MATLAB v4 file with the state matrix as a matrix named A (or another name passed as matrixName). Some common routes (consult your tool's manual for the exact syntax of your version):

  • Any tool that runs Modelica functions in its scripting: once you have A as a Real matrix, Modelica.Utilities.Streams.writeRealMatrix("lin.mat", "A", A, format="4") writes it in the required format.
  • Dymola: the linearizeModel command writes the linearization to dslin.mat, where the state matrix is the upper-left nx × nx block of the matrix ABCD; extract that block and write it as A. The Modelica_LinearSystems2 library returns A directly.
  • OpenModelica: the linearize scripting command (or ModelicaSystem.linearize() in OMPython) gives A, B, C, D.
  • Tools with a linearization feature in their GUI or API (e.g. a linearize custom function in Modelon Impact, SimulationX, MapleSim, Wolfram System Modeler): export A and convert it as below.
  • An FMU, from any exporting tool: FMI 2.0 and 3.0 provide the directional derivatives from which A follows (for instance PyFMI's get_state_space_representation()), or difference the state derivatives numerically.
  • Python, whatever produced A: scipy.io.savemat("lin.mat", {"A": A}, format="4").

Two things to keep consistent between the linearization and the check: the operating point (linearize where the requirement is stated, e.g. after initialization or at a settled time, not at whatever instant the tool defaults to), and the number of states nx given to the check model, which must be the size of the file's A. Tools may choose different states for the same model, but the eigenvalues of A do not depend on that choice.

Step 2: a check model

model CheckPlantEigenvalues
  parameter String file = Modelica.Utilities.Files.loadResource("modelica://MyLib/Resources/lin.mat");
  parameter Integer nx = 4;
  parameter Real A[nx, nx](each fixed=false);
  inner Requirements.Verify.PrintViolations printViolations(evaluationTime=1);
  Requirements.LinearAnalysis.EigenvalueCheck damping(nx=nx, A=A,
    metric=Requirements.Types.EigenMetric.Damping, bound=0.3);
  Requirements.Verify.Requirement R1(text="Every mode shall be damped at least 0.3",
    property=damping.y);
initial equation
  A = Requirements.LinearAnalysis.readStateMatrix(file, nx);
  annotation(experiment(StopTime=1));
end CheckPlantEigenvalues;

Examples.Elementary.LinearAnalysis.SecondOrder is a complete example on a shipped file.

A mode table instead of a state matrix

A finite-element modal run or an experimental modal analysis gives the modes themselves: per mode a frequency, often a damping ratio, and the effective-mass fractions. Read them with readModeColumn and check them with ModeTableCheck and ModesWithinRegion, with no state matrix. These blocks give the same margins as the state-matrix blocks on the same modes, and can also select the modes by effective mass. Examples.Elementary.LinearAnalysis.ModeTable is a complete example.

Not covered

The frequency-response family of linear requirements (gain and phase margin, bandwidth, resonance peak, dc and envelope gain, sensitivity peak, delay margin) has no blocks here, by decision: it needs the complex evaluation of the transfer function over a frequency grid and a crossover search, which no MSL function provides. Evaluate those on the linearization outside Modelica.

Copyright © 2026 Model Based Innovation LLC. All rights reserved.

Contents

NameKindDescription
readStateMatriximpure functionThe A matrix of a linearization from a MATLAB v4 file
modesfunctionThe modes of a state matrix: its eigenvalues with conjugate pairs folded into their Im >= 0 member, the integrator rule and the parasitic cut applied, sorted by magnitude
EigenvalueCheckblockOne eigenvalue predicate over every mode of a state matrix (optionally in a frequency band): Property and margin, constant over the run
EigenvaluesWithinRegionblockEvery mode of a state matrix inside a polygon of the (Re, Im) plane: Property and margin, constant over the run
readModeColumnimpure functionOne column of a mode table (MA-HS-CSV: mode, f, zeta, meff_x, ...) by its header name
hasModeColumnimpure functionWhether a mode table has a column of this name
columnIndexfunctionThe 1-based index of a name in a comma-separated header (quotes and blanks ignored: a name holds neither), 0 when it is not there
eigenvaluesOfModesfunctionThe eigenvalue (Im >= 0 member of the pair) of each mode of a table: (-zeta w, w sqrt(1 - zeta^2)), w = 2 pi f
stateMatrixOfModesfunctionThe block-diagonal state matrix of a mode table: one block [0, 1; -w^2, -2 zeta w] per mode
ModeTableCheckblockOne eigenvalue predicate over every mode of a mode table (optionally in a frequency band, optionally above an effective-mass fraction): Property and margin, constant over the run
ModesWithinRegionblockEvery mode of a mode table inside a polygon of the (Re, Im) plane: Property and margin, constant over the run
propertyPerModefunctionThe property of one eigenvalue predicate per mode (Undefined outside the band)
marginPerModefunctionThe raw margin of one eigenvalue predicate per mode (0 outside the band, -inf for a non-decaying mode against a time constant)
regionMarginsfunctionThe signed distance of every mode (and its conjugate) to a polygon, positive inside
worstMarginfunctionThe least margin over the decided modes (-inf where a violated mode has none, 0 when no mode is decided)