subs
R2026bSymbolic substitution
Syntax
Description
Substitute Variables, Functions, or Subexpressions
replaces all occurrences of exprnew = subs(expr,match,replacement)match in expr with
replacement, evaluates the expression, and returns the result as a
symbolic expression.
If
matchandreplacementare both vectors or cell arrays of the same size, thensubsreplaces each element ofmatchwith the corresponding element ofreplacement.If
matchis a scalar andreplacementis a vector or matrix, thensubsreplaces all instances ofmatchwithreplacement, performing all operations element-wise. The function replaces all constant terms inexprwith the constant multiplied by a vector or matrix of all ones.If
exprinvolves symbolic matrix variables or matrix functions, thenreplacementandmatchmust be the same size.
replaces all occurrences of the default symbolic variable in exprnew = subs(expr,replacement)expr
with replacement, evaluates the expression, and returns the result as
a symbolic expression. The default variable is defined by symvar(expr,1).
Substitute Using Pattern Matching
Since R2026b
performs pattern-based substitution by finding subexpressions in exprnew = subs(expr,match,replacement,Wildcards=vars)expr
that match the pattern match and replacing them with
replacement, treating the variables specified in
vars as wildcards.
Examples
Input Arguments
Output Arguments
Tips
subs(expr,__)does not modifyexpr. To modifyexpr, useexpr = subs(expr,__).If
expris a univariate polynomial andreplacementis a numeric matrix, usepolyvalm(sym2poly(expr),replacement)to evaluateexpras a matrix. The function replaces all constant terms with the constant multiplied by an identity matrix.