# Substituting variables inside a matrix

I'm trying to substitute some dependent variables into equations inside of a matrix, however $Replace[]$ and and $/.$ don't seem to work.

The equation in question is just a vector matrix of differential equations, which I eventually intend to solve.

 NTISE =
{
{((-(Ωc2^2 - I*γ*Ωo1))*a[t] + Ωd2^2*b[t] +        2*I*Ωo1*Derivative[1][a][t])/Ωo1},
{(Ωd2^2*a[t] + (Ωc2^2 + I*γ*Ωo1)*b[t] +           2*I*Ωo1*Derivative[1][b][t])/Ωo1},
{((-Ωc2^2 + 2*Ωe^2 + I*γ*Ωo2)*c[t] + Ωd2^2*d[t] + 2*I*Ωo2*Derivative[1][c][t])/Ωo2},
{(Ωd2^2*c[t] + (Ωc2^2 + 2*Ωe^2 + I*γ*Ωo2)*d[t] +  2*I*Ωo2*Derivative[1][d][t])/Ωo2}
}


And the expressions I would like to substitute in are

ΔΩ1 = Ωc2^2/Ωo1
ΔΩ2 = Ωc2^2/Ωo2
ωd1 = Ωd2^2/Ωo1
ωd2 = Ωd2^2/Ωo2


These expressions should simplify the DEs above in order to get equations that can then be solved, however, I tried using

NTISE /.
{  Ωc2^2/Ωo1 ->  ΔΩ1,
Ωc2^2/Ωo2 ->  ΔΩ2,
Ωd2^2/Ωo1 ->  ωd1,
Ωd2^2/Ωo2 ->  ωd2}


To no avail, and furthermore attempted

Replace[NTISE,
{  Ωc2^2/Ωo1 ->  ΔΩ1,
Ωc2^2/Ωo2 ->  ΔΩ2,
Ωd2^2/Ωo1 ->  ωd1,
Ωd2^2/Ωo2 ->  ωd2}, Infinity]


And got the same equations out.

• You can kind of trick it by slightly rewriting the replacement expression and using it as a rule NTISE /. {\[CapitalOmega]c2^2 -> \[CapitalDelta]\[CapitalOmega]1, \ \[CapitalOmega]c2^2 -> \ \[CapitalDelta]\[CapitalOmega]2*\[CapitalOmega]o2, \ \[CapitalOmega]d2^2 -> \[Omega]d1*\[CapitalOmega]o1, \ \[CapitalOmega]d2^2 -> \[Omega]d2*\[CapitalOmega]o2} // Simplify Jul 18 '18 at 19:22
• Im sorry, I'm not familiar with this method, could you make it clearer for me? Jul 18 '18 at 20:08
• Specifically, I can't figure out the difference between what you wrote and what I tried Jul 18 '18 at 20:15
• I used rules to do the replacement e.g. a*b->c would replace instances of a*b in the expression before the ReplaceAll which has a shorthand /.. Then I changed your replacement rules by multiplying both sides by the denominator. Instead of \[CapitalOmega]c2^2/\[CapitalOmega]o1 -> \[CapitalDelta]\ \[CapitalOmega]1 I wrote \[CapitalOmega]c2^2 -> \ \[CapitalDelta]\[CapitalOmega]1*\[CapitalOmega]o1 Jul 18 '18 at 20:19
• So two questions. 1. the replaceall (/.) stays where it is in my expression? And 2. I just multiply by the denom and mathematica replaces the numerator symbol with my symbol*denom and it simplifies out to what I want it to? Jul 18 '18 at 20:22

By expanding NTISE the denominators are distributed among individual terms, so that ReplaceAll rules match the denominators once per rule.

Simplify[Expand[NTISE] /.
{  Ωc2^2/Ωo1 -> ΔΩ1,
Ωc2^2/Ωo2 -> ΔΩ2,
Ωd2^2/Ωo1 -> ωd1,
Ωd2^2/Ωo2 -> ωd2}]


returns:

{
{I (γ + I ΔΩ1) a[t] + ωd1 b[t] + 2 I a'[t]},
{ωd1 a[t] + (I γ + ΔΩ1) b[t] + 2 I b'[t]},
{(I γ - ΔΩ2 + (2 Ωe^2)/Ωo2) c[t] + ωd2 d[t] + 2 I c'[t]},
{ωd2 c[t] + (I γ + ΔΩ2 + (2 Ωe^2)/Ωo2) d[t] + 2 I d'[t]}
}


For example, looking at the first term of NTISE,

$$\frac{-\left(\text{\Omega c2}^2 + i \gamma \text{\Omega o1}\right)a[t] + \text{\Omega d2}^2 b[t]+2 i \text{\Omega o1} a'[t]}{\text{\Omega o1}}$$

expanding the expression gives:

$$i \gamma a[t]-\frac{\text{\Omega c2}^2 a[t]}{\text{\Omega o1}}+\frac{\text{\Omega d2}^2 b[t]}{\text{\Omega o1}} + 2 i a'[t]$$

which allows ReplaceAll to match the rules Ωc2^2/Ωo1 -> ΔΩ1 and Ωd2^2/Ωo1 -> ωd1.