I have an equation of symbolic vectors (in fact, usually many equations) that I'd like to substitute with a different symbolic vector. I would like MATLAB to substitute the equation with the new symbolic variables such that none of the old ones remain. I have been using the subs function, but it seems to jump at the earliest chance to use a substitution, rather than substituting exactly.
Here is an example of what I mean:
>> M = sym('m',[1,4]).'
M =
m1
m2
m3
m4
>> N = sym('n',[1,4]).'
N =
n1
n2
n3
n4
>> eqn = N(2,1) + 2*N(3,1) - 4*N(4,1)
eqn =
n2 + 2*n3 - 4*n4
>> relation = [N(1,1);N(4,1); N(3,1) - 2*N(4,1); N(2,1)]
relation =
n1
n4
n3 - 2*n4
n2
>> subs(eqn,relation,M)
ans =
m4 - 4*m2 + 2*n3
By hand, I can clearly see that eqn == m4 + 2*m3 exactly. Yet when I ask MATLAB to substitute, I am still left with +2*n3 in the equation.
I have searched around for similar issues to little avail, how can I make MatLab substitute ALL occurrences of n in my equation?
I will usually have many such equations, and I know that it is possible to substitute with m's exactly.