difficulty to use "sin" function

조회 수: 10 (최근 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.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by