Substitutions

To replace all occurrences of a variable in an expression with a number, another variable, or an expression, select the expression and do the following:

  1. Click "substitute" on the Symbolic toolbar to insert the keyword "substitute," followed by an equation with placeholders on either side of the equal sign.

    substitute keyword with equation

  2. Type the variable var that you want to replace in the placeholder to the left of the equal sign.
  3. Type the number, variable, or expression that you want to substitute for var in the placeholder to the right of the equal sign.

    substitute keyword with substitution equation

  4. Press [Enter] or click outside the region.

This replaces all occurrences of the variable var with expr.

Alternatively, you can press [Ctrl] [Shift] [.] and type the keyword "substitute," followed by a comma, in the placeholder that appears. Then type an equation of the form var = expr, using the Boolean equals sign.

Examples:

5x2 + 3x + 9 substitute, x = 2 → 35

5x2 + 3x + 9 substitute, x = s + t → 5 · (s + t)2 + 3 · s + 3 · t + 9

x + y substitute, x = 13 → 13 + y

To substitute values for additional variables, type a comma plus a comma-separated list of additional equations of the form var = expr, again using the Boolean equals sign.

For example:

x + y substitute, x = 13, y = 12 → 25

Note: If you have previously assigned a value to the variable you are substituting for, you might not get the result you expect. For example,

x:= 5

x + 1 substitute, x = 53 → 6

The reason this happens is that Mathcad first replaces x with its assigned value 5 in the second line, and then evaluates the expression 5 + 1. After it does so, it interprets the second line as

6 substitute, 5 = 53

Since 5 does not appear in the expression, Mathcad does not make any substitution: it simply returns the answer 6.

To avoid this problem, you can either clear the substitution variable's symbolic value by typing x:= x, as described in Clearing the Symbolic Value of a Variable, or use the keyword "explicit" to temporarily suppress the assigned value of x as follows:

Using explicit with substitute

Notes:

Related Topics