difficulty to use "sin" function

6 ビュー (過去 30 日間)
parham kianian
parham kianian 2020 年 5 月 13 日
コメント済み: Stephen23 2020 年 5 月 13 日
Consider following:
T = 0.02; %period (sec)
w = 2 * pi / T; %w = 314.1593, angqular frequency (rad/sec)
t = 0 : 0.01 : 20; %time vector (sec)
x = sin(w*t);
plot(t,x)
What is wrong with MATLAB? A sine plot does not look like above. When I set w = 314.1593, the above figure will be plotted. Sine function is a periodic function. But above plot is something completely different. Maximum value should be equal to 1.0 but it is about 10e-12. I cannot figure out where is the problem?
  1 件のコメント
Stephen23
Stephen23 2020 年 5 月 13 日
You are plotting integer multiples of pi:
>> w*t(1:8)
ans =
0.00000 3.14159 6.28319 9.42478 12.56637 15.70796 18.84956 21.99115
What is sine of any integer multiple of pi ?

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

採用された回答

Mehmed Saad
Mehmed Saad 2020 年 5 月 13 日
Either increase you sampling rate
T = 0.02; %period (sec)
w = 2 * pi / T; %w = 314.1593, angqular frequency (rad/sec)
t = 0 : 0.001 : 20; %time vector (sec)
x = sin(w*t);
plot(t,x)
or add a phase in sin
T = 0.02; %period (sec)
w = 2 * pi / T; %w = 314.1593, angqular frequency (rad/sec)
t = 0 : 0.01 : 20; %time vector (sec)
x = sin(w*t+pi/10);
plot(t,x)

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 5 月 13 日
Your w is approximately 100*pi and your t values are all integer multiples of 1/100 . When you multiply the two together, you get an integer multiple of 1/100 * 100*pi which will give you an integer multiple of pi. sin() of an integer multiple of pi is 0 to within round-off error. SO what you are plotting is just round-off error.

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by