필터 지우기
필터 지우기

Output of symoblic expression coming out incorrectly

조회 수: 3 (최근 30일)
cocopuffs
cocopuffs 2015년 4월 11일
댓글: cocopuffs 2015년 4월 11일
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
cocopuffs
cocopuffs 2015년 4월 11일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Roger Stafford
Roger Stafford 2015년 4월 11일
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
Star Strider
Star Strider 2015년 4월 11일
One clue is in the documentation for Find a Default Symbolic Variable:
‘If you do not specify an independent variable when performing substitution, differentiation, or integration, MATLAB uses a default variable. The default variable is typically the one closest alphabetically to x or, for symbolic functions, the first input argument of a function. To find which variable is chosen as a default variable, use the symvar(f, 1) command.’
I’m not sure this demystifies, but it helps explain some of the occasionally arcane choices the Symbolic Toolbox makes.
Roger Stafford
Roger Stafford 2015년 4월 11일
편집: Roger Stafford 2015년 4월 11일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by