# Using the Replace function [closed]

How can I replace two variables at once with Replace[] ? Can't find how to do this. I tried

Replace[x^2+y^2, {x -> a, y -> b}]


but does not work...

## closed as off-topic by MarcoB, m_goldberg, march, Henrik Schumacher, SumitMar 9 at 8:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, m_goldberg, march, Henrik Schumacher, Sumit
If this question can be reworded to fit the rules in the help center, please edit the question.

• Replace[x^2 + y^2, {x -> a, y -> b}, 2]? – J. M. will be back soon Mar 8 at 12:40
• You could also use ReplaceAll: ReplaceAll[x^2 + y^2, {x -> a, y -> b}]. It is worth reading the documentation for these two functions to see how they differ. – Carl Lange Mar 8 at 12:44

You are on the right lines with Replace, but I would rather use a List of replacement rules to achieve this; as mentioned in comments, this is contained in a function called ReplaceAll. You can define your desired original polynomial, and then act on it using /. to replace things as desired. In your case, I would write something like:
x^2+y^2/.{x->a, y->b}