Hello all,
I am trying to replace a term in an equation with a single letter. For example:
R=(a+b)/(c0-c1+g)^2
I want to replace (c0-c1+g)^2 with AA, so that the resulting expression will be:
R=(a+b)/A
How can I do that?
Best regards
Konstantinos
Here is the sentence I always repeat to myself:
When replacement doesn’t work look at the FullForm.
In[1]:= R = (a + b)/(c0 - c1 + g)^2;
FullForm[R]
Out[2]//FullForm= Times[Plus[a, b], Power[Plus[c0, Times[-1, c1], g], -2]]
For your example I want to replace that Power term with another term. But I want that new term to remain in the denominator so I still want that to have an exponent. So I try this
In[3]:= R = R /. Power[Plus[c0, Times[-1, c1], g], -2] -> A^-1
Out[3]= (a + b)/A
And that worked on the first try! That is often not the case.
Another way, using Solve:
(a + b)/(c0 - c1 + g)^2 /. Solve[(c0 - c1 + g)^2 == A, c0]