# Substituting variables in an equation

I wanted to see what would happen if I took

    (E^(-3 (1 + d) t) (1 + 3 d + 2 E^(3 (1 + d) t) -
E^((-3 - d) t + 3 (1 + d) t) - 3 d E^((-3 - d) t + 3 (1 + d) t) +
6 E^((-3 - d) t + 3 (1 + d) t) C[1] +
6 d E^((-3 - d) t + 3 (1 + d) t) C[1]))/(6 (1 + d))


And substituted

1/(3 + 3 d) + C[1]


for some arbitrary variable w

So I wrote:

(E^(-3 (1 + d) t) (1 + 3 d + 2 E^(3 (1 + d) t) -
E^((-3 - d) t + 3 (1 + d) t) - 3 d E^((-3 - d) t + 3 (1 + d) t) +
6 E^((-3 - d) t + 3 (1 + d) t) C[1] +
6 d E^((-3 - d) t + 3 (1 + d) t) C[1]))/(6 (1 + d)) /.
1/(3 + 3 d) + C[1] -> w


And I got the same output as input:

So I am wondering how to substitute out the C1s and replace them with w. Thank you for your help.

• it works for me. Did you try with clean kernel? !Mathematica graphics Jul 27, 2019 at 13:21
• Yes, I've added a picture. Jul 27, 2019 at 13:41
• So ClearAll[t,d] didn't work, but ClearAll[t,d,x,y,w] did. However, all it did was to give me the initial expression with no modifications. I want to get rid of the C1s and to put in w. How do I make mathematics do this? I'll edit the question accordingly. Jul 27, 2019 at 13:49
• I want to get rid of the C1s and to put in w then just do stuff /. C[1] -> w Jul 27, 2019 at 13:57
• What I meant was: I want to get rid of the C1s in such a way that 1/(3 + 3 d) + C[1] -> w . So there are no C1s remaining but w is in the expression Jul 27, 2019 at 14:00

If the objective is to replace the C[1], write your replacement that way.

expr /. C[1] -> w - 1/(3 + 3 d) // Simplify
(*
(1 + 2*E^(3*(1 + d)*t) + E^(2*d*t)*(-3 + 6*w) + d*(3 + E^(2*d*t)*(-3 + 6*w)))/
(E^(3*(1 + d)*t)*(6*(1 + d)))
*)


The pattern to the left of -> must match the FullForm of the subexpression you're attempting to rewrite, and for a complicated subexpression, that's tricky.

Does this produce the result you are looking for?

(E^(-3 (1 + d) t) (1 + 3 d + 2 E^(3 (1 + d) t) -
E^((-3 - d) t + 3 (1 + d) t) -
3 d E^((-3 - d) t + 3 (1 + d) t) +
6 E^((-3 - d) t + 3 (1 + d) t) C[1] +
6 d E^((-3 - d) t + 3 (1 + d) t) C[1]))/(6 (1 + d)) /. C[1] -> w