1

Brand new user here. How to substitute values of multiple variables into an expression?

I try:

n + m /. {n, m} -> {2, 4}
# produces `m+n` as output
# or alternatively 
n + m /. n->2, m->4
# gives blank output

n+5 ./ n->2 works and produces 7 as output.

Is ./ only for single variable substitutions?

Smithey
  • 121
  • 4
  • 2
    n + m /. Thread[{n, m} :> {2, 4}] would be one way – user1066 Aug 10 '20 at 19:08
  • 3
    n + m /. {n->2, m->4}. Useful to understand difference between Replace and ReplaceAll (.) for future work. – PaulCommentary Aug 10 '20 at 19:15
  • 4
    Here's some advice that helped me a lot when I was a new user: use the documentation! It's not that bad! There is a convenient way to access it: highlight the function in question (in this case, highlight the /.) and hit F1 to access the documentation on that function (which is ReplaceAll). Two of the examples under Basic Examples show you exactly what you need. – march Aug 10 '20 at 20:11

0 Answers0