MATLAB Answers

Creating new symbolic identities

7 views (last 30 days)
Daniel Lyddy
Daniel Lyddy on 27 Jun 2014
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?

  0 Comments

Sign in to comment.

Answers (1)

Christopher Creutzig
Christopher Creutzig on 1 Sep 2014
Works for me:
>> syms x y z
>> S = x^2+y^2+z^2+x+y+z+1
S =
x^2 + x + y^2 + y + z^2 + z + 1
>> subs(S, x^2+y^2+z^2, 1)
ans =
x + y + z + 2
Here's something else you might want to try, since it also handles cases that are a bit more “hidden”:
>> assume(x^2+y^2+z^2==1)
>> S
S =
x^2 + x + y^2 + y + z^2 + z + 1
>> simplify(S)
ans =
x + y + z + 2
>> simplify(x^3+x*y^2-x)
ans =
-x*z^2

  0 Comments

Sign in to comment.

Sign in to answer this question.