Don't get what is happening in matlab sin() function. need to know difference between sin(2*50*pi*t) and sin(2*1*pi*t)

8 Ansichten (letzte 30 Tage)
Hi,
I am using Matlab to plot the sin graph. But when I put sin(2*50*pi*t) it shows something else than the sinusoidal curve. Can you please help me to find out why it is happening? Thanks in advance.
Code:
t = 0:0.1:20;
x = sin(2*50*pi*t);
y = sin(2*1*pi*t);
subplot(2,1,1)
plot(t,x)
subplot(2,1,2)
plot(t,y)
  1 Kommentar
Steven Lord
Steven Lord am 9 Sep. 2022
It wouldn't help in this case but if you're computing the sine of pi times some angle, consider using the sinpi function instead of explicitly computing pi times the angle and calling sin.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Torsten
Torsten am 9 Sep. 2022
t1 = 0:0.001:1;
x = sin(2*50*pi*t1);
t2 = 0:0.1:1;
y = sin(2*1*pi*t2);
subplot(2,1,1)
plot(t1,x)
subplot(2,1,2)
plot(t2,y)
  3 Kommentare
John D'Errico
John D'Errico am 9 Sep. 2022
Bearbeitet: John D'Errico am 9 Sep. 2022
@William Rose - I almost wish you had made your comment an answer. While @Torsten is completely correct, he has not made this important point explicit, as did you. And while I could move your comment to an answer, I'd rather let you do it, or not as you desire.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

William Rose
William Rose am 9 Sep. 2022
In your original code, you were evaluating sin(t) at integer multiples of pi, and therefore sin(t)=0 at each point. Due to round-off error, the values are not exactly zero, but are <10^-12.
@Torsten demonstrates that by changing the values of t, you can see that it is a normal sine wave.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by