Here is a simple example using ReplaceAll
:
rvec[[2]] /. rvec -> {x, y}
I think Mathematica first tries to evaluate rvec[[2]]
, realising this is not a list, and only afterwards uses ReplaceAll
. The warning output confirms this.
If instead of rvec[[2]]
we have some complex expression (e.g. inversion of a matrix), Mathematica will to do it analytically first before making the substitution. This is not what I intend, I want to delay the evaluation of rvec[[2]]
(or other more complex things in its place) until the ReplaceAll
substitution has been done.
How can I tell Mathematica to substitute first, then evaluate?
With[{rvec = {x,y}}, rvec[[2]]]
? $\endgroup$