stringToMdss

Method of stringParser.

Assemble an mdss model from expanded polynomial equation strings.

Source: src/utilities/@stringParser/stringToMdss.m

Syntax

sys = stringParser.stringToMdss(str_cell, Ts)
sys = stringParser.stringToMdss(str_cell, Ts, symbols)
sys = stringParser.stringToMdss(str_cell, Ts, symbols, symbolicParameters, numericParameters)

Description

stringToMdss is the final stage of the parsing pipeline symbolicToMdsspolynomialToMdssstringToMdss. It expects each equation already written as a sum of monomials in implicit form, and turns the set of equations into an mdss object.

Each equation string is split into terms at the +/- signs that lie outside parentheses. Every variable token is located by role and index (xp1, x1, u1, y1, z1, …) and removed from its term, leaving the coefficient behind; this yields the incidence (structure) information for each role. State-delta and state variables are scanned together, so an xp index always produces a matching x row even when that row is all zeros. The leftover coefficients are collected into a symbolic parameter matrix.

Symbolic parameters are substituted by their numeric values. If any symbolic variable remains unresolved afterwards, the function raises an error listing the offending names. The resulting structure matrix and parameter matrix are wrapped in a CPNTensor, from which the mdss object is built together with the signal index vectors [stateDelta, state, input, algebraic, binary] and the counts of equality and inequality rows.

Equations beginning with 0 > are treated as inequality rows; the rest are equalities.

Symbols

The third argument maps each variable role to its symbol prefix, in the order

[stateDelta, state, input, algebraic, binary]

with default ["xp", "x", "u", "y", "z"]. You may supply fewer symbols: the list is taken as a prefix of the five roles and the missing trailing roles keep their default names, so ["xp","x"] parses a pure ODE system with no inputs, algebraic or binary variables.

Input arguments

Argument Description
str_cell Cell array of equation strings, each an expanded sum of monomials in implicit form (e.g. "0 = f1*xp1 + f2*x1 + f3*u1"). Multiplication must be explicit (*).
Ts Sample time: 0 continuous-time, >0 discrete-time.
symbols (optional) role symbols, default ["xp","x","u","y","z"].
symbolicParameters (optional) symbolic parameters to substitute.
numericParameters (optional) numeric values, aligned with symbolicParameters.

Output arguments

Output Description
sys The assembled mdss model.

Example

str_cell = {"0 = f1*xp1 + f2*x1 + f3*u1"; ...
            "0 = f4*y1 + f5*x1"};

sys = stringParser.stringToMdss( ...
        str_cell, 0, ["xp","x","u","y","z"], ...
        sym(["f1","f2","f3","f4","f5"]), [1, -0.5, 1, 1, -1]);

See also

mdss · polynomialToMdss · symbolicToMdss


Authors: Torben Warnecke.


MyToolbox Documentation | Generated automatically by CI/CD pipeline