Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have generated a matrix using Mathematica,

$\left( \begin{array}{ccc} \text{cos$\theta $} & -\text{sin$\theta $} & \text{cos$\theta $}\, \text{dx}+\text{dx}-\text{dy}\, \text{sin$\theta $} \\ \text{sin$\theta $} & \text{cos$\theta $} & \text{cos$\theta $} \,\text{dy}+\text{dy}+\text{dx}\, \text{sin$\theta $} \\ 0 & 0 & 1 \\ \end{array} \right)$

Now I want to change the variable names $dx$ to $xr$ and $dy$ to $yr$. How could I do this?

share|improve this question
up vote 5 down vote accepted

You can do it programmatically using Replace. For example:

{{1, 1, 1}, {1, dx, x^2}, {1, dy, du^2}} /. {dx -> s, dy -> "hello"}

replaces the dx with s and the dy with "hello". You can choose your own replacements. To understand what this actually means, consider the longer form:

Replace[{{1, 1, 1}, {1, dx, x^2}, {1, dy, du^2}}, {dx -> s, dy -> "hello"}, 2]

which shows that you want to replace the specified items in the second level (the "2") of the matrix.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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