Consider the TreeForm
of expr
:
expr = Subscript[x,
i] + (-Subscript[x, -1 + i] + Subscript[x, i]) Subscript[\[Zeta],
1 + i] + ((Subscript[gf, -1 + i] +
Subscript[gh, i]) Subscript[\[Zeta], 1 + i] -
Subscript[gf,
i] (1 + Subscript[\[Zeta], 1 + i] + Subscript[\[Eta], 1 + i]) -
Subscript[gh,
1 + i] (1 + Subscript[\[Zeta], 1 + i] +
Subscript[\[Eta], 1 + i]))/L
I have labeled the Tree such that the L
in the denominator is marked as "p" and this branch needs to appear with "q". As well as "p" needs to appear as a multiplier for the simplified form of "r" and "s".
The following step is required:
Subscript[gf,
i] (1 + Subscript[\[Zeta], 1 + i] + Subscript[\[Eta], 1 + i]) -
Subscript[gh,
1 + i] (1 + Subscript[\[Zeta], 1 + i] + Subscript[\[Eta],
1 + i]) // Simplify
$$\left(\text{gf}_i-\text{gh}_{i+1}\right) \left(\zeta _{i+1}+\eta _{i+1}+1\right)$$
Initially I wanted to MapAt
the function Simplify
at this location but I am still struggling with it so some rule-therapy is in order:
expr /. Times[Power[p_], Plus[q_, r_, s_]] :> Plus[
Times[Power[p], q], Times[Power[p], Simplify[Plus[r, s]]]]
$$-\frac{\left(\text{gf}_i+\text{gh}_{i+1}\right) \left(\zeta _{i+1}+\eta _{i+1}+1\right)}{L}+\frac{\zeta _{i+1} \left(\text{gf}_{i-1}+\text{gh}_i\right)}{L}+\zeta _{i+1} \left(x_i-x_{i-1}\right)+x_i$$