I have a matrix expression involving three real symbolic variables called x, y, and z, which are three elements of a vector v in R3. It is known that v is constrained to be a unit vector, so that x^2 + y^2 + z^2 is always equal to 1. Is there a way to tell MATLAB about this identity (x^2 + y^2 + z^2 = 1) so that whenever it encounters the expression x^2 + y^2 + z^2, it substitutes a 1 for that expression?
I tried using subs(S, x^2 + y^2 + z^2, 1), but that doesn't work ... it appears the second argument to a three-argument subs() call has to be a single variable.
I tried the following trick, inspired by the conversion from Cartesian to Spherical coordinates:
syms a b real;
s1 = subs(S, x, cos(a) * sin(b));
s2 = subs(s1, y, sin(a) * sin(b));
s3 = subs(s2, z, cos(b));
and that actually performs the x^2 + y^2 + z^2 = 1 substitution, but has the unfortunate side effect that all remaining expressions are now in terms of a and b instead of x, y, and z.
There has to be a way to do this, right? Corallary: I can't be the first person who has wanted something like this, can I?