Goal: I want to multiply all constant factors in an expression by 2. For example,
4 x^2 (4 Subscript[a, 1] + Subscript[a, 2] - 7 Subscript[c, 4])
should be transformed to
8 x^2 (8 Subscript[a, 1] + Subscript[a, 2] - 14 Subscript[c, 4])
However, I don't want the replacement to apply for powers (such as x^2
) and subscripts.
On my attempt to explicitly name the expressions that should be changed (which would be too much work anyway because it's not a generic solution) replacement also affects power and subscripts:
4 x^2 (4 Subscript[a, 1] + Subscript[a, 2] - 7 Subscript[c, 4]) /. 2 -> 4 (* wrong *)
(A solutions that turns Subscript[a, 2]
in 2 Subscript[a, 2]
would also be fine.)
expr //. {x^p_ -> x^p, Subscript[i_, j_] -> Subscript[i, j], n_Integer -> 2*n}
Improvement allowed. I have installed Mathematica for 6 hours now and I am just starting to learn. Thanks $\endgroup$1
? Shouldx
become ` 2 x`? $\endgroup$