Skip to main content

Exploring Calculus with Maple Introductory Calculus

Section 9.2 Making a Substitution into an Expression

Let’s suppose you have assigned an expression a name, and wish to replace one of its variables with a value or expression. As an example, we will assign an expression a name of expr and then substitute the numerical value for \(\pi\text{,}\) which is denoted as Pi in Maple, into expr. The command used to substitute a value into an expression is subs().
> expr := sin(x) - 1;
\begin{equation*} \displaystyle expr\, := \,\sin \left( x \right) -1 \end{equation*}

Aside

> subs(x = Pi, expr);
\begin{equation*} \displaystyle \sin \left( \pi \right) -1 \end{equation*}
The order of the parameters in the subs() command is important. For example, giving the expression before the substitution will give an error:
> subs(expr,x = Pi);
Error, invalid input: subs received sin(x)-1, 
which is not valid for its 1st argument
You can make use of the % shortcut if you wish, but recall that it is best used on the same Maple input:
> x^2 + 3*x - 4; subs(x = 2, %);
\begin{equation*} \displaystyle {x}^{2}+3\,x-4 \end{equation*}
\begin{equation*} \displaystyle 6 \end{equation*}
You can also substitute one expression into another:

Aside

> expr2 := tan(2*x) + 1;
\begin{equation*} \displaystyle expr2\, := \,\tan \left( 2\,x \right) +1 \end{equation*}
> subs(x = a+h, expr2);
\begin{equation*} \displaystyle \tan \left( 2\,a+2\,h \right) +1 \end{equation*}