Once you have used a symbolic variable in an expression, assigning a new value to the variable almost always leads to confusion and bugs. The situation is very much like
and then expecting that B will have changed from 2 to 3 because B was assigned in terms of A and A has changed. It does not work that way numerically and it does not work that way symbolically: every use of a symbolic variable takes a copy of its current value.
MATLAB almost never goes by variable name. Even
is not going by variable name: instead it is making use of command / function equivalence and calling
which is (for this purpose) effectively defined as
assignin('caller', name, sym(name));
which is to say, almost equivalent to
After that, every reference to x would resolve to its current value, which would be sym('x') until it was reassigned. But as soon as you reassign a numeric value to it, then the references to x resolve to the numeric value instead, including in subs() . This is normal MATLAB processing, and it is necessary. For example if you define
syms R1, R2, R3
vars = [R1, R2, R3];
subs(Expression, vars, [5, 6, 8])
then you need vars to resolve to its value which is the vector of names: you would not want vars to be treated as sym('vars') just because it appears in the second position in a subs() call.
Remember, pretty much every reference to a variable (that is not on the left side of an assignment) is to be resolved by value.
If "The first solution seems acceptable ...barely" and avoiding assigning values over top of symbol names is not acceptable at all, then you need to find yourself a different programming language -- one that is not MATLAB, Scilab, Octave, Maple, fortran, C, C++, or perl. As I recall you would also need to avoid Mathematica, and IDL, but it has been some time since I have used those so I could be forgetting some of their quirks.