ApplySubstitutions - MapleSim Help

ApplySubstitutions

apply variable and parameter substitutions

 Calling Sequence A := MapleSim:-LinkModel(); A:-ApplySubstitutions(expr, options)

Parameters

 expr - expression, can be any algebraic expression, equation, or a set, list, Vector, or Matrix of expressions and equations options - (optional) equation(s) of the form name = value

Returns

 • given expression where substitutions that are applied to variable and parameter names in other API function calls (or, optionally, the reverse of these substitutions) were applied

Options

 • reverse : true or false
 Specifies whether the reverse of the substitutions that are used in all API calls are applied to expr. Default is false.

Description

 • A:-ApplySubstitutions returns the given expression where variable and parameter names have been substituted using the substitutions that were applied to variable and parameter names in other API function calls (or the reverse of these substitutions, if the reverse option was passed).
 • The A := MapleSim:-LinkModel() statement needs to be run prior to successfully using any of the ModelObject A's export functions.

Examples

Linking to a MapleSim model (located in .msim file):

 > $A≔\mathrm{MapleSim}:-\mathrm{LinkModel}\left('\mathrm{filename}'=\mathrm{cat}\left(\mathrm{kernelopts}\left('\mathrm{toolboxdir}'=\mathrm{MapleSim}\right),"/data/examples/RLCcircuit.msim"\right)\right):$

Get equations without substitutions and apply the substitutions using the ApplySubstitutions command:

 > $\mathrm{eqs}≔A:-\mathrm{GetEquations}\left('\mathrm{nosubs}'\right)$
 ${\mathrm{eqs}}{≔}\left\{{\mathrm{Main.RLC.C1.p.i}}{}\left({t}\right){+}{\mathrm{Main.RLC.I1.p.i}}{}\left({t}\right){-}{\mathrm{Main.RLC.SC1.v}}{}\left({t}\right){-}{\mathrm{sin}}{}\left({2}{}{\mathrm{\pi }}{}{t}\right){=}{0}{,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\mathrm{Main.RLC.I1.p.i}}{}\left({t}\right){=}{-}{\mathrm{Main.RLC.SC1.v}}{}\left({t}\right){,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\mathrm{Main.RLC.SC1.v}}{}\left({t}\right){=}{-}{\mathrm{Main.RLC.C1.p.i}}{}\left({t}\right)\right\}$ (1)
 > $A:-\mathrm{ApplySubstitutions}\left(\mathrm{eqs}\right)$
 $\left\{{\mathrm{C1_p_i}}{}\left({t}\right){+}{\mathrm{I1_p_i}}{}\left({t}\right){-}{\mathrm{SC1_v}}{}\left({t}\right){-}{\mathrm{sin}}{}\left({2}{}{\mathrm{\pi }}{}{t}\right){=}{0}{,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\mathrm{I1_p_i}}{}\left({t}\right){=}{-}{\mathrm{SC1_v}}{}\left({t}\right){,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\mathrm{SC1_v}}{}\left({t}\right){=}{-}{\mathrm{C1_p_i}}{}\left({t}\right)\right\}$ (2)

Check that it is equivalent to getting equations with substitutions:

 > $A:-\mathrm{GetEquations}\left(\right)$
 $\left\{{\mathrm{C1_p_i}}{}\left({t}\right){+}{\mathrm{I1_p_i}}{}\left({t}\right){-}{\mathrm{SC1_v}}{}\left({t}\right){-}{\mathrm{sin}}{}\left({2}{}{\mathrm{\pi }}{}{t}\right){=}{0}{,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\mathrm{I1_p_i}}{}\left({t}\right){=}{-}{\mathrm{SC1_v}}{}\left({t}\right){,}\frac{{ⅆ}}{{ⅆ}{t}}\phantom{\rule[-0.0ex]{0.4em}{0.0ex}}{\mathrm{SC1_v}}{}\left({t}\right){=}{-}{\mathrm{C1_p_i}}{}\left({t}\right)\right\}$ (3)

Obtain the original variable names by applying the reverse substitutions to the variables:

 > $\mathrm{vars}≔A:-\mathrm{GetVariables}\left(\right)$
 ${\mathrm{vars}}{≔}\left[{\mathrm{C1_p_i}}{}\left({t}\right){,}{\mathrm{I1_p_i}}{}\left({t}\right){,}{\mathrm{SC1_v}}{}\left({t}\right)\right]$ (4)
 > $A:-\mathrm{ApplySubstitutions}\left(\mathrm{vars},'\mathrm{reverse}'\right)$
 $\left[{\mathrm{Main.RLC.C1.p.i}}{}\left({t}\right){,}{\mathrm{Main.RLC.I1.p.i}}{}\left({t}\right){,}{\mathrm{Main.RLC.SC1.v}}{}\left({t}\right)\right]$ (5)

Check that it is equivalent to getting variables without substitutions:

 > $A:-\mathrm{GetVariables}\left('\mathrm{nosubs}'\right)$
 $\left[{\mathrm{Main.RLC.C1.p.i}}{}\left({t}\right){,}{\mathrm{Main.RLC.I1.p.i}}{}\left({t}\right){,}{\mathrm{Main.RLC.SC1.v}}{}\left({t}\right)\right]$ (6)