Output of symoblic expression coming out incorrectly

1 view (last 30 days)
cocopuffs
cocopuffs on 11 Apr 2015
Commented: cocopuffs on 11 Apr 2015
Hi guys,
I am using the code pasted below with the corresponding output:
syms X w t p
eq = X*cos(w*t - p)
eq =
X*cos(p - t*w)
The output is is reversed it should instead be X*cos(w*t - p). How would I change this?
  1 Comment
cocopuffs
cocopuffs on 11 Apr 2015
Roger Stafford is correct. I forgot cos had that property. I graphed my solutions using both configurations and got the same values.
I was thinking about the sin function because the order actually matters. Thank you for clearing that up.

Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 11 Apr 2015
The two expressions are identically equal for the cosine function, just as t*w and w*t are identically equal because of the commutative law of multiplication. The symbolic toolbox has a tendency to rearrange expressions in accordance with some criteria unknown to us mere mortals, provided the result is still identically equal.
  2 Comments
Roger Stafford
Roger Stafford on 11 Apr 2015
Somehow I doubt that a default symbolic variable was involved in this particular instance. It looks like the typical rearrangement that often occurs to symbolic expressions due to - well, call it "simplification" - in this case it put the variables in alphabetical order, but nevertheless following specific rules of equivalence. My own ancient copy of the Symbolic Toolbox often does such peculiar things.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by