subs
Symbolic substitution
Syntax
Description
Substitute Symbolic Scalar Variables and Functions
returns a copy of snew
= subs(s
,match
,replacement
)s
, replacing all occurrences of
match
with replacement
, and then evaluates
s
. Here, s
is an expression of symbolic scalar
variables or a symbolic function, and match
specifies the symbolic
scalar variables or symbolic function to be substituted.
If
match
andreplacement
are both vectors or cell arrays of the same size,subs
replaces each element ofmatch
with the corresponding element ofreplacement
.If
match
is a scalar, andreplacement
is a vector or matrix, thensubs(s,match,replacement)
replaces all instances ofmatch
ins
withreplacement
, performing all operations element-wise. All constant terms ins
are replaced with the constant multiplied by a vector or matrix of all ones.
returns a copy of snew
= subs(s
,replacement
)s
, replacing all occurrences of the default
symbolic scalar variable in s
with replacement
,
and then evaluates s
. The default variable is defined by symvar(s,1)
.
Substitute Symbolic Matrix Variables and Functions
returns a copy of sMnew
= subs(sM
,matchM
,replacementM
)sM
, replacing all occurrences of
matchM
with replacementM
, and then evaluates
sM
. Here, sM
is an expression, equation, or
condition involving symbolic matrix variables and matrix functions, and
matchM
specifies the symbolic matrix variables and matrix functions
to be substituted. The substitution values replacementM
must have the
same size as matchM
. (since R2021b)
returns a copy of sMnew
= subs(sM
,replacementM
)sM
, replacing all occurrences of the default
symbolic matrix variable in sM
with
replacementM
, and then evaluates sM
. (since R2021b)
Examples
Input Arguments
Tips
subs(s,__)
does not modifys
. To modifys
, uses = subs(s,__)
.If
s
is a univariate polynomial andreplacement
is a numeric matrix, usepolyvalm(sym2poly(s),replacement)
to evaluates
as a matrix. All constant terms are replaced with the constant multiplied by an identity matrix.