Back to Symbolic Mathematics

subs

Substitute in symbolic expression

Syntax

g = subs(f, old, new)
g = subs(f, var, value)

Description

Substitutes old with new in the symbolic expression f. Can substitute a variable with a value or an expression with another expression. Useful for evaluating symbolic expressions at specific values or simplifying by replacement.

Parameters

NameDescription
fSymbolic expression
oldSymbol or expression to replace
newReplacement value or expression

Returns

Expression with substitution applied

Examples

Try It
>> syms x; subs(x^2 + 1, x, 2)
5
Try It
>> syms x y; subs(x + y, x, y^2)
y^2 + y

See Also