Why do I get "sin(t)^2" when I "int(sin(2*t))"?

1 回表示 (過去 30 日間)
Peter Hammond
Peter Hammond 2018 年 9 月 17 日
コメント済み: Peter Hammond 2018 年 9 月 17 日
I enter the following at the start of a Matlab session:
t = sym('t'); y = sin(2*t); int(y)
Matlab returns the following: ans = sin(t)^2
This is clearly not correct. It should return -cos(2*t)/2. Any other number in the cosine argument besides "2" seems to give the correct answer (e.g. if y = sin(3*t), int(y) returns -cos(3*t)/3). I've tried this in v2014b as well as v2016a. Simulink does the same thing if you integrate the function sin(2*t). Either this is a bug, or I'm going insane!

採用された回答

Dimitris Kalogiros
Dimitris Kalogiros 2018 年 9 月 17 日
編集済み: Dimitris Kalogiros 2018 年 9 月 17 日
Results of int(), are correct. Actually sin(t)^2 and -cos(2t)/2 differ only by a constant 1/2.
And this is legal, since at every integral we can consider a constant that is added to the result.
  3 件のコメント
Steven Lord
Steven Lord 2018 年 9 月 17 日
The NIST Handbook of Mathematical Functions has a section with trigonometric function identities. On this page, equation 4.21.28 states that cos(2*x) = 1-2*sin^2(x) So through a little manipulation of that identity you can see what Dimitris said is true, the expression you expected and the expression Symbolic Math Toolbox provided differ only by a constant.
So this is not a bug and you're not going insane. The packaging looks different, but the contents inside the package are the same.
Peter Hammond
Peter Hammond 2018 年 9 月 17 日
Thank you both! I get it. The offset created by squaring the sine expression threw me off since the negative part of the wave disappeared. It helps to be familiar with the trig identities!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by