Help on trigonometric operations using syms variable.

조회 수: 5 (최근 30일)
iamShreyans
iamShreyans 2019년 9월 7일
댓글: Walter Roberson 2019년 9월 7일
I'm performing trigonometric operations on a syms variable 't4'.
The input is:
sind(t4-90)
The output that I'm getting is 'sin(pi*(t4-90)/180)'. How do I get it displayed in terms of 'cos' instead? I wish to get the answer in a simplified form.
Thanks!

채택된 답변

John D'Errico
John D'Errico 2019년 9월 7일
편집: John D'Errico 2019년 9월 7일
You probably need to use rewrite.
syms t4
S = sind(t4-90)
S =
sin((pi*(t4 - 90))/180)
rewrite(expand(S),'sincos')
ans =
-cos((pi*t4)/180)
I did need to expand the extrpession to get rewrite to work.
rewrite(expand(S),'cos')
would also have worked.
rewrite was introduced in R2012a, so most people should have it.
  댓글 수: 2
iamShreyans
iamShreyans 2019년 9월 7일
편집: iamShreyans 2019년 9월 7일
Thanks a lot for the help John! The 'sind(t4-90)' is actually a term of a matrix that I'm generating using a loop function and there are more such terms inside the matrix. I would be happy to know if there is a way to apply the expand function to all terms of a matrix at once. Also is can the output be obtained in the cosd/sind functions? I don't wish to see the pi/180 term to make my output more readable.
Walter Roberson
Walter Roberson 2019년 9월 7일
expand(YourMatrix) does work on all entries in the matrix.
It is not possible to see the output in terms of sind and cosd without going to a bunch of bother writing MuPad procedures. In r2019a and later there are functions that make it a lot easier do mapping transformation that would be able to narrow down to sin and cos terms and extract and manipulate their arguments, but very shortly after you substituted the sind and cosd equivalents, matlab would see that those were function calls and would evaluate them which would promptly rewrite back to sin and cos.

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by