0
$\begingroup$

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...

$\endgroup$

closed as off-topic by MarcoB, m_goldberg, march, Henrik Schumacher, Sumit Mar 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.

  • 5
    $\begingroup$ Replace[x^2 + y^2, {x -> a, y -> b}, 2]? $\endgroup$ – J. M. is away Mar 8 at 12:40
  • 6
    $\begingroup$ 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. $\endgroup$ – Carl Lange Mar 8 at 12:44
1
$\begingroup$

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}
(* a^2+b^2 *)

Is this what you needed?

$\endgroup$
  • $\begingroup$ Yes, thank you :) $\endgroup$ – rodger_kicks Mar 8 at 15:54
  • $\begingroup$ You're welcome. The comments are more often than not a more useful place to start. Have a read of the Generalisations or Examples in documentation and tutorials as well. $\endgroup$ – Brad Mar 8 at 15:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.